4

By specifying the term set guid we can get all the terms, but the term sets can have multiple levels. So how can I get all the child terms of a specific parent term in a term set? Because a term set can have multiple parent terms.

I am working on SharePoint online, so I need to get it using JSOM. Basically given the parent term GUID how to get its child elements?

7

The following example demonstrates how to get all child terms of a specific parent term using Taxonomy JSOM API

var context = SP.ClientContext.get_current();
var session = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
var termStore = session.getDefaultSiteCollectionTermStore();

var parentTermId = '7c43575c-282d-41a3-b20a-f6629bdc4808'; //parent Term Id
var parentTerm = termStore.getTerm(parentTermId);
var terms = parentTerm.get_terms();  //load child Terms


context.load(terms);
context.executeQueryAsync(
function(){
   //print child Terms
   for(var i = 0; i < terms.get_count();i++){
       var term = terms.getItemAtIndex(i);
       console.log(term.get_name());
   }

}, 
function(sender,args){
  console.log(args.get_message());    
});
2

Here is good blog, he explain and gave the examples using JSOM API for Taxonomy. he write the code for, how to access the Taxonomy Term Store, how to iterate through all the items. How to add a Group, TermSet and Term, and lastly how to delete them.

Accessing Taxonomy Term Store with JSOM

http://sympmarc.com/2013/10/11/spservices-stories-18-retrieve-managed-metadata-using-javascript-and-spservices/

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.