0

I am using following code get all the terms using GUID.

var context = SP.ClientContext.get_current();
var session = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
var termStore = session.getDefaultSiteCollectionTermStore();
var parentTermId = '894e81d3-c0d5-477d-952f-582ba564fa1b'; //parent Term Id
var parentTerm = termStore.getTerm(parentTermId);
var terms = parentTerm.get_terms();  //load child Terms
context.load(terms, 'Include(IsRoot, Labels, TermsCount, CustomSortOrder, Id, IsAvailableForTagging, Name, PathOfTerm, Parent, TermSet.Name)');
context.executeQueryAsync(
function(){
   //print child Terms
   for(var i = 0; i < terms.get_count();i++){

    var term = terms.getItemAtIndex(i);
    var term_name = term.get_name();
    var term_parent = term.get_parent();
    var terms_count = term.get_termsCount();
    }
  }, function(sender,args){
   console.log(args.get_message());    
 });

Presently I am getting the term count property properly. I want to list out all the labels present inside the term.

Keerthi Kumar
  • 168
  • 2
  • 13

1 Answers1

0

I want to list out all the labels present inside the term.

SP.Taxonomy.Term.labels property - gets a collection of Label objects for the current Term object.

In your example labels could be printed like this:

for(var i = 0; i < terms.get_count();i++){
   var term = terms.getItemAtIndex(i);
   //...

   //print labels of term  
   term.get_labels().get_data().forEach(function(lbl){
      console.log(lbl.get_value());     
   });
}
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • Dear Vadim, I am looking for something like following code var currentTerm = termEnumerator.get_current(); var termOrder = currentTerm.get_customSortOrder(); var orders = termOrder.split(':'); for (var i = 0; i < orders.length; i++) { var key = orders[i]; // key is the term Guid // do something, you're looping through children in the correct Custom Sort Order } Here, I am able to get the GUID of the labels. How to get the name of the labels? – Keerthi Kumar Jun 26 '18 at 06:12