blog.scoreman.net

Get term store in SharePoint Online

This is just ta small tips when working with taxonomy client-side object model and SharePoint Online. You will find lots of examples like the one below online:

var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
var termStores = taxSession.get_termStores();
var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");

The important thing to note is that the name of the term store (something like Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==) can and will change over time. This can happen if the service (Office 365) creates a new Managed Metadata Service Application or even fails over to another data center. To prevent the code from crashing a better approach could be to use getDefaultSiteCollectionTermStore:

var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
var termStores = taxSession.get_termStores();
var termStore = taxSession.getDefaultSiteCollectionTermStore();

Leave a Reply