4

I'm trying to display the terms of a site but I can't create a instance of TermSession object.

context = SP.ClientContext.get_current();
var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);

This code displays the following error (firebug):

TypeError: b.get_path is not a function SP.Taxonomy.TaxonomySession.getTaxonomySession()

I've tried in two different SharePoint 2013 environments (online and in premise)

Am I missing something?

Thanks!

  • 1
    Did you load sp.taxonomy.js script file from _layouts/15 ? – JayHell Jan 27 '16 at 14:17
  • Yes, I did. The error is inside the getTaxonomySession method – Nicolas Dimov Jan 27 '16 at 15:44
2

I think I found my mistake... It's seems that sp.runtime.js has to be loaded manually.

<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.taxonomy.js"></script>
<script type="text/javascript">

$(document).ready(function(){       
    SP.SOD.executeFunc('SP.Runtime.js', 'SP.Runtime', function () {
        SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function () {
            SP.SOD.executeFunc('SP.Taxonomy.js', 'SP.Taxonomy', loadTerms)
        });
    });
});

And then I could load my terms normally.

context = SP.ClientContext.get_current();
var session = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
context.load(session);
var termStore = session.getDefaultSiteCollectionTermStore();
context.load(session);
context.load(termStore);
context.executeQueryAsync(
    function () {
        var termStoresEnum = termStore.getEnumerator();

Thanks for the advice.

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.