In order to add term under a parent term, you need:
- The Term store ID and relevant Term set
- The Parent Term ID (to which the new child term will be added)
The code:
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());
});}