Get name of Term from Managed metadata service by Guid

2018-04-20 09:47:44

function execOperation() {

var context = SP.ClientContext.get_current();

//Current Taxonomy Session

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

//Term Stores

var termStores = taxSession.get_termStores();

//Name of the Term Store from which to get the Terms.

var termStore = termStores.getByName(att["data-termname"]);

$.each(att["data-termset"].split(','), function (i, x) {

var termSet = termStore.getTermSet(x); //Guid // 5719b9cf-8da0-4a03-bc33-f47c81fb696a

console.log(termSet.get_name()); // <- this one dont work ofc.

var terms = termSet.getAllTerms();

context.load(terms);

context.executeQueryAsync(function () {

var termEnumerator = terms.getEnumerator();

while (termEnumerator.moveNext()) {

var currentTerm = termEnumerator.get_current().$2_0.$K_0;

var TermPath = currentTerm.PathOfTerm.split(';');