3
var myTerm = getTermInfo('term name');

specially i need to get the GUID of the term, i know that after getting guid i can get all the other properties of that particular term.

1

You can get the store (by name) then the SP.Taxonomy.TermCollection and then the term by name.

Based on: Working with Taxonomy and JavaScript in SharePoint 2013

$(document).ready(function(){   

    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_name");

    //GUID of Term Set from which to get the Terms.
    var termSet = termStore.getTerms();

    var terms = termSet.getAllTerms().getByName("term name");

    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());

    });

}

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.