In Term store management "Managed_Metadata_Service", I have "My TermSet" that have terms.
I want to display the terms from a term store and "My TermSet" by Unique Identifier and using Javascript Object Model. How can this be done?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityIn Term store management "Managed_Metadata_Service", I have "My TermSet" that have terms.
I want to display the terms from a term store and "My TermSet" by Unique Identifier and using Javascript Object Model. How can this be done?
I am able to list terms in a term set of my default term store using following code.
var test = {};
ExecuteOrDelayUntilScriptLoaded(spready, "sp.js");
function spready() {
var scriptbase = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/";
$.getScript(scriptbase + "SP.Taxonomy.js", function () {
var termID = "8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f";
var clientContext = SP.ClientContext.get_current();
var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(clientContext);
termStore = taxonomySession.getDefaultSiteCollectionTermStore();
var termSet = termStore.getTermSet(termID);
test.terms = termSet.get_terms();
clientContext.load(taxonomySession);
clientContext.load(termStore);
clientContext.load(termSet);
clientContext.load(test.terms);
clientContext.executeQueryAsync(onTermSucceeded, onTermFailed);
});
}
function onTermSucceeded(sender, args) {
console.log("term success:");
console.log(test.terms);
}
function onTermFailed(sender, args) {
alert('Termset Error: ' + args.get_message());
}
You may also take a reference of below blog:
BR