1

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?

2

Login to the portal using SharePoint admin credentials.

After that, go to the below url:

https://yourtenantname-admin.sharepoint.com/_layouts/15/termstoremanager.aspx

It will open the term store in the admin site.

Now go to the term set in the term store.

Ensure that available for tagging check box is checked as below. After that save the termset.

enter image description here

It should work now.

If the error still persists, try the below refactored code:

var termSetId = "99197470-943b-43d1-8375-209fb75251f6"; 

var context = SP.ClientContext.get_current();
var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
var termStore = taxonomySession.getDefaultSiteCollectionTermStore();
var termSet = termStore.getTermSet(termSetId);
var terms = termSet.getAllTerms();
  • Ha. I already had "Available for tagging" enabled, but I was using the guid of the parent group instead of the term set itself, and your screenshot pointed me towards that. Thank you! – Darryl Ashton Jun 15 '17 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.