I'm trying to use this fairly straightforward code:
function getAllTerms() {
var context = new SP.ClientContext.get_current();
SP.SOD.executeFunc("SP.Taxonomy.js", 'SP.ClientContext', function () {
//Current Taxonomy Session
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
console.log(taxSession);
//Term Stores
var termStores = taxSession.get_termStores();
//Name of the Term Store from which to get the Terms.
var termStore = termStores.getByName("Taxonomy_Pu0HiX4GZKMCNnSDgo8P3g==");
//GUID of Term Set from which to get the Terms.
var termSet = termStore.getTermSet("99197470-943b-43d1-8375-209fb75251f6");
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());
});
});
}
But whether I try to use getByName or getDefaultSiteCollectionTermStore, I always get the error:
Cannot invoke method or retrieve property from null object. Object returned by the following call stack is null. "GetTermSet
GetByName
TermStores
Microsoft.SharePoint.Taxonomy.TaxonomySession.GetTaxonomySession
I know there's a possible configuration change in Central Administration to carry out with SharePoint 2013, but this is SharePoint Online, so surely this should just work?