2

I have a list with multi-select managed metadata column. How, preferably using search REST api, get all distinct values from this column from all list rows?

2
  • In REST Api there is no distinct operation. So you can get all terms in the metadata column and use for your operation. Let me know if you need that. Commented Jun 10, 2017 at 14:03
  • If it's not possible using rest api, then yes, I need that. How could I do it?
    – pilifi
    Commented Jun 10, 2017 at 19:58

1 Answer 1

2

Using following JSOM you can get terms by term set name.

function getTermsByTermSetName(termSetName, callback) {                  
    var context = SP.ClientContext.get_current();               
    var session = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
    var termStore = session.getDefaultSiteCollectionTermStore(); 
    termSets = termStore.getTermSetsByName(termSetName,1033); 
    context.load(session);
    context.load(termStore); 
    context.load(termSets);

    context.executeQueryAsync(       
    function () {
        var termSetEnum = termSets.getEnumerator();
        if(termSetEnum.moveNext()){
            var currentTermSet = termSetEnum.get_current();      
            //Load terms         
            var terms = currentTermSet.get_terms();      
            context.load(terms);         
            context.executeQueryAsync(       
            function () {        
                var termsEnum = terms.getEnumerator();
                var termsList = [];      
                while (termsEnum.moveNext()) {       
                    var currentTerm = termsEnum.get_current();       
                    var termName = currentTerm.get_name();       
                    var termId = currentTerm.get_id();       
                    termsList.push(termName);        
                }   
                //alert(termsList); 
                callback(termsList);
            },       
            function () {        
                //failure to load terms.
            });
        }        
    },       
    function () {        
        //failure to load current term set       
    });
}

getTermsByTermSetName("term set name", function(terms) {
//execute your logic to bind terms
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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