I am trying to use JSOM to programmatically activate the SharePoint Server Publishing Infrastructure feature at the Site collection level:
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?