2

Most of this code comes from an answer to a previous question. I'm trying to take it one step further now and get the actual default label string.

var context = SP.ClientContext.get_current();          
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);  
var term = taxSession.getTerm('f06b442f-81db-4356-acc7-2c565fe3bf00'); 
var defaultLabel = term.getDefaultLabel(); 
console.log(defaultLabel);
3

1 Answer 1

1

Use SP.Taxonomy.Term.getDefaultLabel Method to get the default Label for this Term based on the LCID:

function getTermDefaultValue(termId,lcid,success,failure)
{
    var context = SP.ClientContext.get_current();         
    var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);  
    var termDefaultValue = taxSession.getTerm(termId).getDefaultLabel(lcid);
    context.executeQueryAsync(function() {
           success(termDefaultValue);
        },
        failure);
}

Note: SP.Taxonomy.Term.getDefaultLabel method expects locale identifier (LCID) for the label.

Example:

var layoutsRoot = _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/';    
$.getScript(layoutsRoot + 'sp.taxonomy.js',
   function () {
      var termId = 'dff82ab5-6b7a-4406-9d20-40a8973967dd';   
      getTermDefaultValue(termId,1033,printLabelInfo,printError);
});


function printLabelInfo(label)
{
    console.log(String.format('Default Label: {0}',label.get_value()));
}


function printError(sender,args){
    console.log(args.get_message());
}    

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.