enter image description here

I want to display the terms from a term store using Javascript Object Model. How can this be done?


I have blogged about it here: http://www.vrdmn.com/2012/12/working-with-taxonomy-and-javascript-in.html

The code:


    var scriptbase = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/";

    $.getScript(scriptbase + "SP.Runtime.js",
        function () {
            $.getScript(scriptbase + "SP.js", function(){

                $.getScript(scriptbase + "SP.Taxonomy.js", execOperation);



function execOperation(){

    //Current Context
    var context = SP.ClientContext.get_current();

    //Current Taxonomy Session
    var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);

    //Term Stores
    var termStores = taxSession.get_termStores();

    //Name of the Term Store from which to get the Terms.
    var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");

    //GUID of Term Set from which to get the Terms.
    var termSet = termStore.getTermSet("b49f64b3-4722-4336-9a5c-56c326b344d4");

    var terms = termSet.getAllTerms();



    var termEnumerator = terms.getEnumerator();

    var termList = "Terms: \n";


            var currentTerm = termEnumerator.get_current();

            termList += currentTerm.get_name() + "\n";







I have added a input button with ID btnTaxonomies, which is fetching the Terms from the Terms store using JSOM

$(document).ready(function () {
        $('#btnTaxonomies').click(function () {
            SP.SOD.registerSod('sp.taxonomy.js', SP.Utilities.Utility.getLayoutsPageUrl('sp.taxonomy.js'));
            $('#btnTaxonomies').val("Getting Taxonomies, please wait...");
            SP.SOD.executeFunc('sp.taxonomy.js', false, Function.createDelegate(this, function () {
                var context = SP.ClientContext.get_current();
                var taxonomySession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
                var termStore = taxonomySession.get_termStores().getByName("Managed Metadata Service");
                var termSet = termStore.getTermSet("e51ca15d-a805-460e-ba5d-8f539b88cbdf");
                var terms = termSet.getAllTerms();
                context.executeQueryAsync(Function.createDelegate(this, function (sender, args) {
                    var termsEnumerator = terms.getEnumerator();
                    var menuItems = new Array();
                    $('#btnTaxonomies').val("Get the navigation Taxonomies");
                    while (termsEnumerator.moveNext()) {
                        var currentTerm = termsEnumerator.get_current();
                        document.write("<br>Name: " + currentTerm.get_name());

                }), Function.createDelegate(this, function (sender, args) {
                    alert('The error has occured: ' + args.get_message());

I think there is already a similar question which has an answer for you. Query SP2013 Managed metadata term store

  • I tried that code. Specified argument was out of the range of valid values.Parameter name: index Getting the above error – Darshan Rane Oct 1 '13 at 11:18

I figured it out, don't know whether its perfect way out, for now it works...

Used TaxonomyHiddenList to get the list of terms

var oListTax = context.get_web().get_lists().getByTitle('TaxonomyHiddenList');
var camlQuery = new SP.CamlQuery();

collListItemTax = oListTax.getItems(camlQuery);

    var listItemEnumerator = collListItemTax.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItemTax = listItemEnumerator.get_current();
  • 3
    I would never advise to use the hidden list to do that. – KoenVosters Apr 20 '16 at 12:27

Loading SharePoint TermStore is very easy. you have load default terms and then have to get the term store by name. and also you can get additional properties of the term store. you can get more details in this article. This Article may be helpful for you. Please mark it as answer if it is helpful.


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.