Skip to content

Instantly share code, notes, and snippets.

@princeppy
Forked from vman/sp15_taxAllTerms.js
Created July 18, 2018 13:42
Show Gist options
  • Select an option

  • Save princeppy/bf3ce89e6fe960883b0e472744c86e83 to your computer and use it in GitHub Desktop.

Select an option

Save princeppy/bf3ce89e6fe960883b0e472744c86e83 to your computer and use it in GitHub Desktop.
$(document).ready(function(){
var scriptbase = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js",
function () {
$.getScript(scriptbase + "SP.js", function(){
$.getScript(scriptbase + "SP.Taxonomy.js", execOperation);
});
}
);
});
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();
//Name of the Term Store from which to get the Terms.
var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");
//GUID of Term Set from which to get the Terms.
var termSet = termStore.getTermSet("b49f64b3-4722-4336-9a5c-56c326b344d4");
var terms = termSet.getAllTerms();
context.load(terms);
context.executeQueryAsync(function(){
var termEnumerator = terms.getEnumerator();
var termList = "Terms: \n";
while(termEnumerator.moveNext()){
var currentTerm = termEnumerator.get_current();
termList += currentTerm.get_name() + "\n";
}
alert(termList);
},function(sender,args){
console.log(args.get_message());
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment