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!

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

1 Answer 1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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