1

I am trying to use JSOM to programmatically activate the SharePoint Server Publishing Infrastructure feature at the Site collection level:

SharePoint Server Publishing Infrastructure

I ran the following script:

var publishingSiteFeatureId = 'f6924d36-2fa8-4f0b-b16d-06b7250180fa';

var clientContext = SP.ClientContext.get_current();
var site = clientContext.get_site();

site.get_features().add(new SP.Guid(publishingSiteFeatureId), false, SP.FeatureDefinitionScope.farm);
clientContext.executeQueryAsync(function() {
  console.log('SUCCESS!');
}, function(request, response) {
  console.log('ERROR', response.get_message());
});

Two and a half minutes after running, I finally get a response: the error Unexpected response from server. and upon checking, the feature has not been enabled. However, about a minute later I check again and the feature is now enabled.

Is there any way I can modify my script to get a reliable response when the feature is successfully activated?

  • Problem is that even in UI it ends with an error almost every time. But it seems that feature is activated properly. So I don’t think you are able to to create better script then you have now. Mayby try to activat it again, with force set to true, if error occurs. – Lukas Nespor Feb 1 at 5:22
  • Look through your ULS logs. Reactivate SPSPI Feature and use a tool like UlsViewer to inspect it in live mode. Like Lukas said, sometimes SP is weird and throws errors but everything works. Likewise, sometimes no error is thrown but everything is broken suddenly. Only way to make sure is to click around and create publishing sites and content and look through ULS for any errors. – LeonidasFett Feb 1 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.