How do I access salesforce custom labels in a snippet? I tried $A.get("$Label.Name_Of_Label") but it doesnt seem to be working.

  • 1
  • Question
  • Updated 2 years ago
  • Answered
Access Custom Label
Photo of Kalyan Kuchi

Kalyan Kuchi

  • 176 Points 100 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
"$A" is the shorthand for Aura in lightning components, I don't think that will work with skuid, I think you want something like this:

skuid.utils.mergeAsText("global","{{$Label.Name_Of_Label}}")

That should work according to these links:

http://help.skuidify.com/m/11720/l/187263-global-merge-variables-functions

http://help.skuidify.com/m/11720/l/129517-skuid-utils
Photo of Kalyan Kuchi

Kalyan Kuchi

  • 176 Points 100 badge 2x thumb
Hi Moshe,

I tried these approaches but they doesnt seem to be working. I am looking to use the labels in javascript. 

I tried something like this but no luck. 

var testLabel = {$Label.LABEL_NAME};
console.log(testLabel);


Any other ideas?

KR.
(Edited)
Photo of Ryan Paddy

Ryan Paddy

  • 578 Points 500 badge 2x thumb
Hi Kalyan,

Moche's approach works for me. 

You will need to add the Custom Label to the Skuid page first before it can be accessed by this method or in a merge template, otherwise that method will just return an empty string. 

Ryan
Photo of Kvin Cloud

Kvin Cloud

  • 262 Points 250 badge 2x thumb
Hi Ryan,

I am trying to access a label as shown below:

var specialSegment = skuid.utils.mergeAsText("global","{{$Label.Special_Partner}}");

but have got an error saying :
skuid__SkuidJS:26 Uncaught TypeError: Cannot read property 'organizationId' of undefined

Any idea on how to utilize this method from utils ?
Photo of Ryan Paddy

Ryan Paddy

  • 578 Points 500 badge 2x thumb
Hi Kvin,

That code looks okay. 

Are you sure your error isn't being thrown by a different line of code? Look for a line that attempts to access a field called organizationId on an object. 

Have you tried debugging using console.log or alert statements?
Photo of Kvin Cloud

Kvin Cloud

  • 262 Points 250 badge 2x thumb
Hi Ryan,

Thanks for taking time to respond on this.
I got this working.

The reason was : The Skuid.utils.userInfo object is only available once the page is loaded.

So if you intend to access this in "inline" snippet
$(document.body).one('pageload',function(){

//Here you should be able to access as shown below
 var specialSegment = skuid.utils.mergeAsText("global","{{$Label.Special_Partner}}");    console.log('specialSegment from Label',specialSegment);

});