I'm creating a custom execute JavaScript button for the Opportunity detail page and trying to use an IF statement to conditionally load a resource with REQUIRESCRIPT. The goal is to base the condition on the value of a checkbox (Active__c) on the related Account record. Here's the button formula:


The formula never evaluates to true regardless of the Active__c field being true or false so the REQUIRESCRIPT never loads. If I base the condition on a checkbox on the Opportunity record, it works fine. The click-activated alert displays the correct values for Active__c so the formula is getting something for that field, but it doesn't seem to be able to reference it correctly in the IF statement. Oddly, if I create some other type of condition like Account.Text_Field__c = 'text', it works correctly. The issue seems to be limited to booleans. Is this just a limitation of custom buttons, or am I doing something wrong here?

In this mockup, the JavaScript encoded in the REQUIRESCRIPT is just an alert popup that says 'Hello' when the script loads.

  • Did you try Active__c == 'true' ? ;-)
    – brovasi
    Commented Feb 18, 2014 at 5:57
  • 'true' as a string with quotes errors out because it only accepts a boolean value. I have tried Active__c == true with no success. Active__c != false and the !Active__c don't work either. Commented Feb 18, 2014 at 22:10

2 Answers 2


I think the problem is that REQURIESCRIPT is handled by the server and is one of those few occasions where you can't use a merge field for the parameter. When you tested with a text field did you use == or = as in your example? In the case of the latter it would have done an assignment and fulfilled the condition regardless of the value in the field used.

I'd include the script at the top regardless, but put the code inside the script into a function. Then you can simply call that function or not based on the field's value.



If you absolutely want to use the style you have, and there is a bug with booleans (seems doubtful, but you never know) then a cast might do the trick: {!IF((Account.Active__c & '') == 'true',...

  • The JavaScript in the REQUIRESCRIPT is intended to carry out a task when the page loads rather than when the button is clicked. I use this method to display a jquery pop up alert to the user when they open the opportunity record. Moving the logic into the button JavaScript like you demonstrate makes it dependant on the user clicking the button. (correct?) This is an example of what does work: {!IF( Account.AccountNumber == 'CD656092', REQUIRESCRIPT("data:application/javascript;base64,YWxlcnQoJ2hlbGxvJyk="),'')} alert('{!Account.AccountNumber}') Commented Feb 21, 2014 at 3:04

Please try this code:

    alert('It's alive!'); 
  • This didn't work either. Commented Feb 18, 2014 at 23:19
  • It should not not work like this. I just gave you example without any alert inside. Please try it now. This If must work :) Commented Feb 19, 2014 at 5:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .