Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Is there a way to use a custom label in a javascript custom button ?

for example:

var targetUrl = encodeURI("http://{!$Label.targetHost}/what/ever?user={!$User.Username}");
share|improve this question

2 Answers 2

up vote 6 down vote accepted

That should work fine. I just tested in my org with a custom label called Label with the following Javascript on a custom button:

alert('{!$Label.Label}');

The text I had set up was 'Sample' and when I clicked the custom button on my object it correctly alerted the word Sample.

Are you experiencing something different?

share|improve this answer
    
Thanks for making me test again: be sure to use the right label name ! –  Martin Feb 1 '13 at 15:27
    
No problem. Happens to the best of us! Glad you got it working. –  Jesse Altman Feb 1 '13 at 15:28

This will work, since before displaying web page, all labels tags ("{!$Label.labelName}") will be replace with text values. On page load javascript will be executed with text values.

Although in your example I would consider using custom settings for storing variables such as target host.

share|improve this answer
    
Custom Settings or labels both work. One benefit of labels is that they are included in the metadata when you refresh sandboxes or create a package. –  Daniel Hoechst Feb 1 '13 at 15:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.