Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

in sharepoint managed metadata I found very little documentation on managing terms using javascript CSOM. I could create a taxonomy term directly under the term set but I want to create a term under another term as a child like in term store window.

 function execOperation(){
    //Current Context
    var context = SP.ClientContext.get_current();
    //Current Taxonomy Session
    var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
    //Term Stores
    var termStores = taxSession.get_termStores();
    //Term Store under which to create the term.
    var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");
    //Term Set under which to create the term.
    var termSet = termStore.getTermSet("b49f64b3-4722-4336-9a5c-56c326b344d4");
    //Name of the term, LCID and a new GUID for the term.
    var newTerm = termSet.createTerm("India", 1033, "b49f64b3-4722-4336-9a5c-56c326b344a9");
    //newTerm.set_isAvailableForTagging(true);
    context.load(newTerm);
    context.executeQueryAsync(function(){
    alert("Term Created: " + newTerm.get_name());
     },function(sender,args){
    console.log(args.get_message());
    });
}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

In order to add term under a any parent term, you should be needing two things:

  • The Term store ID and relevant Term set
  • The Parent Term ID (to which the new child term will be added)

The update code will be following:

     function execOperation()
     {
        //Current Context
        var context = SP.ClientContext.get_current();

        //Current Taxonomy Session
        var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);

        //Term Stores
        var termStores = taxSession.get_termStores();

        //Term Store under which to create the term.
        var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");

        //Term Set under which to create the term.
        var termSet = termStore.getTermSet("b49f64b3-4722-4336-9a5c-56c326b344d4");


        //get the parent term ID, say it's "cf46hujkl-3344-4336-9a5c-56c326b344d4"
        var parentTerm = termSet.getTerm("cf46hujkl-3344-4336-9a5c-56c326b344d4");

        //create new child term under the parent term
        var newTerm = parentTerm.createTerm("SharePoint Rocks", 1033, newGuid.toString());

        context.load(newTerm);
        context.executeQueryAsync(function(){
        alert("Term Created: " + newTerm.get_name());
         },function(sender,args){
        console.log(args.get_message());
        });}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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