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?
-
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.– Venkat KonjetiCommented Jun 10, 2017 at 14:03
-
If it's not possible using rest api, then yes, I need that. How could I do it?– pilifiCommented Jun 10, 2017 at 19:58
Add a comment
|
1 Answer
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
});