none
Get taxonomy label based on term guid using javascript RRS feed

  • Question

  • Hi,

    Can you please get me the code to retrieve the term label by giving input as term guid using javascript.

    Thanks,
    Kishore


    Kishore

    Thursday, May 4, 2017 1:19 PM

Answers

  • Hi Kishore,

    The demo below for your reference (the demo is getting all the labels):

    function getLabel(termguid){
       	 var clientContext = SP.ClientContext.get_current();
         var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(clientContext);
       	 var termStores = taxSession.get_termStores();
       	 var termStore = termStores.getByName("Managed Metadata Service");//change the term store name here
       	 var termSet = termStore.getTermSet("b6756f2d-4c5e-418f-8378-60e401d466f5");//change the term set guid here
       	 var term=termSet.getTerm(termguid);
         this.labelColl = term.getAllLabels(1033);
       	 clientContext.load(labelColl);
       	 clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); 
    }
    function onQuerySucceeded(sender, args) {
         var label = '';
       	 var sum='';
         var labelEnumerator = labelColl.getEnumerator();        
       	 while (labelEnumerator.moveNext()) {
           		 label = labelEnumerator.get_current();
           		 var value=label.get_value();
            		if(value!=this.dlabel){
            			sum+=value;
            			sum+=" ";
           		 }	
       	 }  
    }
    function onQueryFailed(sender, args) {
       	 alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
    

    Best Regards,

    Victoria Xia


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Proposed as answer by sadomovalexMVP Friday, May 5, 2017 11:57 AM
    • Marked as answer by Kishorekv Wednesday, June 14, 2017 12:33 PM
    Friday, May 5, 2017 11:51 AM
    Moderator

All replies

  • Hi Kishore,

    The demo below for your reference (the demo is getting all the labels):

    function getLabel(termguid){
       	 var clientContext = SP.ClientContext.get_current();
         var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(clientContext);
       	 var termStores = taxSession.get_termStores();
       	 var termStore = termStores.getByName("Managed Metadata Service");//change the term store name here
       	 var termSet = termStore.getTermSet("b6756f2d-4c5e-418f-8378-60e401d466f5");//change the term set guid here
       	 var term=termSet.getTerm(termguid);
         this.labelColl = term.getAllLabels(1033);
       	 clientContext.load(labelColl);
       	 clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); 
    }
    function onQuerySucceeded(sender, args) {
         var label = '';
       	 var sum='';
         var labelEnumerator = labelColl.getEnumerator();        
       	 while (labelEnumerator.moveNext()) {
           		 label = labelEnumerator.get_current();
           		 var value=label.get_value();
            		if(value!=this.dlabel){
            			sum+=value;
            			sum+=" ";
           		 }	
       	 }  
    }
    function onQueryFailed(sender, args) {
       	 alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }
    

    Best Regards,

    Victoria Xia


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Proposed as answer by sadomovalexMVP Friday, May 5, 2017 11:57 AM
    • Marked as answer by Kishorekv Wednesday, June 14, 2017 12:33 PM
    Friday, May 5, 2017 11:51 AM
    Moderator
  • Hi Kishore,

    I am checking to see how things are going there on this issue. Please let us know if you would like further assistance.

    Best Regards,

    Victoria


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, May 29, 2017 9:00 AM
    Moderator
  • Hi Kishore,

    Is there any update about this issue?

    Best Regards,

    Victoria


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, June 1, 2017 12:08 PM
    Moderator