Fetching Term Store Data
var Tower = [];
var Category = [];
var info = [];
var LoadDocData = [];
var exect=false;
$(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", function () {
context = SP.ClientContext.get_current();
//Call your code here.
execOperation();
});
});
});
});
function execOperation() {
//Current Context
var context = SP.ClientContext.get_current();
//Current Taxonomy Session
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
//Term Stores
var termStoreColl = taxSession.get_termStores();
//Name of the Term Store from which to get the Terms.
var termStoreT = termStoreColl.getByName("Managed Metadata Service");
//GUID of Term Set from which to get the Terms.
var termSetT = termStoreT.getTermSet("257bfe19-ff48-482f-bc22-72cd5f471320");
var termsT = termSetT.getAllTerms();
context.load(termsT);
context.executeQueryAsync(function () {
var termEnumerator = termsT.getEnumerator();
var termList = "Terms: \n";
while (termEnumerator.moveNext()) {
var currentTerm = termEnumerator.get_current();
termList += currentTerm.get_name() + "\n";
var currentTermValue = currentTerm.get_pathOfTerm().split(';');
var currentTermId = currentTerm.get_id().toString();
if (currentTermValue.length == 1) {
var temTower = {
Tower: currentTermValue[0],
TowerId: currentTermId
};
Tower.push(temTower);
}
else if (currentTermValue.length == 2) {
var tempCat = {
Tower: currentTermValue[0],
Category: currentTermValue[1],
CategoryId: currentTermId
}
Category.push(tempCat);
}
else if (currentTermValue.length == 3) {
var tempInfo = {
Tower: currentTermValue[0],
Category: currentTermValue[1],
info: currentTermValue[2],
infoId: currentTermId
}
info.push(tempInfo);
}
}
}, function (sender, args) {
console.log(args.get_message());
});
}
No comments:
Post a Comment