3

I am trying to find a list of all the features on my SharePoint 2013 cloud site using JavaScript.

When I get the context to the site I don't see FeatureDefinitions as part of the site object (SP.ClientContext(url).get_site()) or web object (SP.ClientContext(url).get_web()).

I can retrieve all of the active features for both using get_features(), but this is not what I am looking for.

Am I looking at the wrong object? Is this not doable in JavaScript?

  • 2
    So you are looking to find all the available features (both activated and not activated)? Is my understading correct? – Arvi Mar 1 '16 at 23:57
  • Correct. any solution that is installed on the collection. – Mathieu Corriveau Mar 4 '16 at 15:51
1

It seems there is no way to retrieve the list of available features from the client side, but you could extract this information from Features page as demonstrated below:

function getFeatureDefinitions(scope){       
   var url = SP.Utilities.Utility.getLayoutsPageUrl('ManageFeatures.aspx');
   if(scope == 'Site')
     url+= '?Scope=Site';
   return $.get(url)
          .then(function(data){
              var featureDefs = $(data).find('th#FeatureIcon').closest('table').children('tbody').children('tr').not(':first').map(function() {
                  var featureDef = {};
                  featureDef.title = $(this).find("td:nth-child(2) tr:nth-child(1) td").text().trim(); 
                  featureDef.desc = $(this).find("td:nth-child(2) tr:nth-child(2) td").text().trim();
                  featureDef.id = $(this).find("td:nth-child(3)").find('div').attr('id');
                  return featureDef;
              }); 
              return featureDefs.toArray(); 
          });

}

Usage

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
   getFeatureDefinitions('Site')
   .done(function(featureDefs){
       console.log(JSON.stringify(featureDefs,null,2));
   });

});
  • What if SP site layout changes? :) – Michal Hainc 11 hours ago

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.