if you need to find all terms in you termset that have a custom proepty, you can use this method: SP.Taxonomy.TermSet.getTermsWithCustomProperty(c)
https://msdn.microsoft.com/en-us/library/office/dn312633.aspx
Another Solution:
Based on: https://gist.github.com/zplume/1395dee6b8b2e38e5927
Basically, you call it as
YOURNAMESPACE.Taxonomy.Helper.Function.getTerms(CURRENTSITEURL,GROUPNAME)
and it returns JS Object with all terms, including custom properties.
(function () {
var nsName = "YOURNAMESPACE"; // root namespace name
window.Rise = window.Rise || {};
var ns = window[nsName];
ns.Taxonomy = ns.Taxonomy || {};
ns.Taxonomy.Helper = {
Data: {
Sites: {} // cache for Taxonomy terms JSON
},
// get metadata terms for a term group, in the context of the specified site collection
Function: {
Sites: {}, // JSOM cache for Taxonomy objects
getTerms: function (url, groupName) {
var ctx,
siteData = ns.Taxonomy.Helper.Data.Sites[url] || {},
siteObjects = ns.Taxonomy.Helper.Function.Sites[url] || {};
function getTermGroups() {
ctx = new SP.ClientContext(url);
// Cache TaxonomySession as a global variable to avoid uninitialized error when making multiple requests against the term store (i.e. when querying more than one group)
siteObjects.taxonomySession = siteObjects.taxonomySession || SP.Taxonomy.TaxonomySession.getTaxonomySession(ctx);
siteObjects.termGroups = siteObjects.taxonomySession.getDefaultSiteCollectionTermStore().get_groups();
ctx.load(siteObjects.termGroups);
return ns.Taxonomy.Helper.executeQuery(ctx, siteObjects.termGroups, true);
}
function getTermGroup(termGroups) {
siteObjects.termGroups = termGroups;
siteObjects.termGroup = jQuery.grep(siteObjects.termGroups, function (value, index) {
return value.get_name() == groupName;
})[0];
if (siteObjects.termGroup) {
ctx.load(siteObjects.termGroup);
return ns.Taxonomy.Helper.executeQuery(ctx);
} else {
return jQuery.Deferred().reject("No Group by name '" + groupName + "' was found.").promise(); // don't continue the promise chain
}
}
function getTermSets() {
siteData.TermGroups = siteData.TermGroups || {};
siteData.TermGroups[groupName] = {};
siteObjects.termSets = siteObjects.termGroup.get_termSets();
ctx.load(siteObjects.termSets);
return ns.Taxonomy.Helper.executeQuery(ctx, siteObjects.termSets, true);
}
function getAllTerms(termSets) {
siteObjects.termSets = termSets;
siteData.TermGroups[groupName].TermSets = siteData.TermGroups[groupName].TermSets || {};
var termSetsPromises = jQuery.map(siteObjects.termSets, function (termSet, i) {
return getTermsForTermSet(termSet); // load term set terms async
});
return jQuery.when.apply(jQuery, termSetsPromises) // when all terms are loaded
.then(function () {
ns.Taxonomy.Helper.Data.Sites[url] = siteData;
ns.Taxonomy.Helper.Function.Sites[url] = siteObjects;
return siteData;
})
.done(function () {
return siteData;
});
}
function getTermsForTermSet(termSet, termSetsPromises) {
var termSetName = termSet.get_name();
siteData.TermGroups[groupName].TermSets[termSetName] = {};
siteData.TermGroups[groupName].TermSets[termSetName].Terms = siteData.TermGroups[groupName].TermSets[termSetName].Terms || [];
siteData.TermGroups[groupName].TermSets[termSetName].Props = termSet.get_customProperties();
var terms = termSet.get_terms(),
termsGlobal = siteData.TermGroups[groupName].TermSets[termSetName].Terms;
return getTermsRecursive(terms, termsGlobal);
}
function getTermsRecursive(terms, termsGlobal) {
// populate global variable with terms and child terms recursively
ctx.load(terms);
return ns.Taxonomy.Helper.executeQuery(ctx)
.then(function () {
return getTerms(terms, termsGlobal);
});
}
function getTerms(terms, termsGlobal) {
terms = ns.Taxonomy.Helper.enumerableToArray(terms);
var childTermsPromises = jQuery.map(terms, function (term, i) {
var termName = term.get_name();
var arrayTerm = {};
arrayTerm.Label = termName;
arrayTerm.TermGuid = term.get_id().toString();
arrayTerm.prop = term.get_localCustomProperties();
var url = term.get_localCustomProperties()._Sys_Nav_SimpleLinkUrl;
if (term.get_localCustomProperties().css)
arrayTerm.css = term.get_localCustomProperties().css;
if (Rise.Helper.isItemEmpty(url)) {
arrayTerm.isUrl = false;
} else {
arrayTerm.isUrl = true;
}
arrayTerm.Url = url;
termsGlobal.push(arrayTerm);
arrayTerm.Terms = arrayTerm.Terms || [];
// get child terms
return term.get_termsCount() > 0 ? (function () {
return getTermsRecursive(term.get_terms(), arrayTerm.Terms);
})() : null;
});
return jQuery.when.apply(jQuery, childTermsPromises);
}
return getTermGroups()
.then(getTermGroup)
.then(getTermSets)
.then(getAllTerms);
}
},
enumerableToArray: function (enumerable) {
var enumerator = enumerable.getEnumerator();
var array = [];
while (enumerator.moveNext()) {
var current = enumerator.get_current();
array.push(current);
}
return array;
},
executeQuery: function (ctx, returnObject, toArray) {
var def = new jQuery.Deferred();
ctx.executeQueryAsync(function () {
returnObject ?
toArray ?
def.resolve(ns.Taxonomy.Helper.enumerableToArray(returnObject)) : // resolve returnObject as an array
def.resolve(returnObject) : // resolve returnObject
def.resolve(); // resolve undefined
}, function (sender, args) {
console.log(args);
def.reject(args);
});
return def.promise();
}
};
})();
SP.js
was not being loaded and would time out.