Hello,
currently i am getting an issue for get_customSortOrder of a term.
terms are sorting perfectly which are root level terms but 2nd level / child level terms are not getting custom sort order.
in 2nd level, terms are displaying alphabetically.
can you please suggest what is going wrong with my code.
i have attached my sample code.
var rootElement = new Array(); var targetPageUrlArr = [];
function GetTermsFromTaxonomyStoreForPC() {
//alert(terstoreid);
var context = new SP.ClientContext.get_current();
var termSet = termStore.getTermSet('term set id');
var terms = termSet.getAllTerms();
context.load(terms, 'Include(IsRoot, Labels, TermsCount, CustomSortOrder, Id, IsAvailableForTagging, Name, PathOfTerm, Parent, Parent.Id, TermSet.Name,LocalCustomProperties)');
context.executeQueryAsync(function () {
var chaparray = new Array();
var termEnumerator = terms.getEnumerator();
while (termEnumerator.moveNext()) {
var currentTerm = termEnumerator.get_current();
var term_name = currentTerm.get_name();
var term_id = currentTerm.get_id();
var term_customsortoder = currentTerm.get_customSortOrder();
var term_parent = "";
var terms_count = currentTerm.get_termsCount();
var term_path = currentTerm.get_pathOfTerm();
var term_allterms = currentTerm.getTerms();
var isRoot = currentTerm.get_isRoot();
if (isRoot) {
var imageUrl = currentTerm.get_localCustomProperties()["_Sys_Nav_CategoryImageUrl"] == undefined ? "" : currentTerm.get_localCustomProperties()["_Sys_Nav_CategoryImageUrl"];
termId.push(term_name);
imagePath.push(imageUrl);
}
var nodeTitle = currentTerm.get_localCustomProperties()["_Sys_Nav_SimpleLinkUrl"]; // I am getting undefined
var targetPageUrl = currentTerm.get_localCustomProperties()["_Sys_Nav_TargetUrl"];//== undefined ? "" : currentTerm.get_localCustomProperties()["_Sys_Nav_TargetUrl"];
targetPageUrlArr.push(targetPageUrl);
chaparray.push(nodeTitle);
rootElement.push(term_path);
}
var divcntntsAll = "";
var html = '<ul class="top-level-menu">';
var idcount = 0;
var idarr = [];
for (var i = 0; i < rootElement.length; i++) {
if (rootElement[i].indexOf(';') == -1) {
if (chaparray[i] === 'undefined' || !chaparray[i] || chaparray[i] == null) {
var ind = termId.indexOf(rootElement[i]);
var image = imagePath[ind];
if (image != "") {
if (targetPageUrlArr[i] != undefined) {
html += "<li><a href='" + targetPageUrlArr[i] + "' class='t-l-a'><span class='rootmenu t-l-a'><img src='" + image + "' class='menuicon' /></span></a>";
}
else {
html += "<li><span class='rootmenu t-l-a'><img src='" + image + "' class='menuicon' /></span>";
}
}
else {
if (targetPageUrlArr[i] != undefined) {
html += "<li><a href='" + targetPageUrlArr[i] + "' class='t-l-a'><span class='rootmenu t-l-a'>" + rootElement[i] + " <i class='fa fa-caret-down' id=" + rootElement[i].replace(/ /g, '_') + " style='display:none'></i></span></a>";
}
else {
html += "<li><span class='rootmenu t-l-a'>" + rootElement[i] + " <i class='fa fa-caret-down' id=" + rootElement[i].replace(/ /g, '_') + " style='display:none'></i></span>";
}
}
}
else {
var ind = termId.indexOf(rootElement[i]);
var image = imagePath[imagePath];
html += "<li><a href='" + chaparray[i] + "' class='t-l-a'><img style='width:15px;height:15px; padding-right:3px' src='" + image + "' />" + rootElement[i] + " <i class='fa fa-caret-down' id=" + rootElement[i].replace(/ /g, '_') + " style='display:none'></i></a>";
}
var ss = "";
var divcntnts = "";
for (var j = 0; j < rootElement.length; j++) {
var pagetitl2 = rootElement[j];
var ind2 = rootElement.indexOf(pagetitl2);
var href2 = targetPageUrlArr[ind2];
if (rootElement[j].indexOf(rootElement[i] + ";") > -1) {
var arr2 = rootElement[j].split(';');
idcount++;
if (arr2.length == 2) {
var idd = arr2[0].replace(/ /g, '_');
if (idarr.indexOf(idd) == -1) {
idarr.push(idd);
}
if (chaparray[j] === 'undefined' || !chaparray[j] || chaparray[j] == null) {
ss += "<li><div class='rootmenu product-link' id='link" + idcount + "'>" + arr2[1] + " <i class='fa fa-caret-right' id='arr" + idcount + "' style='display:none'></i></div></li>";
}
else {
ss += "<li><a href='" + href2 + "' id='link" + idcount + "' class='product-link'>" + arr2[1] + " <i class='fa fa-caret-right' id='arr" + idcount + "' style='display:none'></i></a></li>";
}
var ss1 = "<div id='boxlink" + idcount + "' class='licntent boxlink' style='display: none'>";
var childsdiv = "<div style='float:left; padding-left:10px;' id='childsdiv'>";
var divcount = 0;
for (var k = 0; k < rootElement.length; k++) {
var pagetitl3 = rootElement[k];
var ind3 = rootElement.indexOf(pagetitl3);
var href3 = targetPageUrlArr[ind3];
if (rootElement[k].indexOf(rootElement[i] + ";" + arr2[1] + ";") > -1) {
var arr3 = rootElement[k].split(';');
var idd = 'arr' + idcount;
if (idarr.indexOf(idd) == -1) {
idarr.push(idd);
}
if (arr3.length == 3) {
if (href3 != undefined) {
childsdiv += "<span class='fa fa-caret-right'></span><b> <a href='" + href3 + "'>" + arr3[2] + "</a></b><br />";
divcount++;
}
else {
if (href3 == undefined) { childsdiv += "<b>" + arr3[2] + "</b><br />"; }
else { childsdiv += "<b><a href='" + href3 + "'>" + arr3[2] + "</a></b><br />"; }
divcount++;
}
for (var l = 0; l < rootElement.length; l++) {
var pagetitl4 = rootElement[l];
var ind4 = rootElement.indexOf(pagetitl4);
var href4 = targetPageUrlArr[ind4];
if (rootElement[l].indexOf(rootElement[i] + ";" + arr2[1] + ";" + arr3[2] + ";") > -1) {
var arr4 = rootElement[l].split(';');
if (arr4.length == 4) {
if (chaparray[l] != undefined) {
//childsdiv += "<span class='fa fa-caret-right'> </span><a href='" + chaparray[l] + "' target='_blank''>" + arr4[3] + "</a><br />";
childsdiv += "<span class='fa fa-caret-right'> </span><a href='" + chaparray[l] + "'>" + arr4[3] + "</a><br />";
divcount++;
}
else {
childsdiv += "<a href='" + href4 + "'>" + arr4[3] + "</a><br />";
//childsdiv += "<a href='" + href4 + "' target='_blank''>" + arr4[3] + "</a><br />";
divcount++;
}
}
}
}
if (divcount >= 18) {
ss1 += "" + childsdiv + "</div>";
childsdiv = "<div style='float:left; padding-left:10px;'>";
divcount = 0;
}
}
}
}
ss1 += "" + childsdiv + "</div>";
divcntnts = ss1 + "</div>";
}
divcntntsAll += divcntnts;
divcntnts = "";
}
}
html += "<ul class='second-level-menu productlist'>" + ss + "</ul>";
}
}
//alert(html );
html += '</ul>' + divcntntsAll;
$('#metadata').html(html);
for (var i = 0; i < idarr.length; i++) {
$('#' + idarr[i]).show();
}
}, function (sender, args) {
alert('error');
});
}Thanks.
anuj