Find your content:

Search form

You are here

Button Validation Logic


I came across a simple example for validating that when a button is clicked, it verifies that something is true or false in the Record before allowing the normal button logic.


if(ISBLANK({!Opportunity.Amount})) {
alert ("Opportunity Amount cannot be blank");
} else {
*** would be normal result here ****
*** such as:'/500/e?retURL=%2F500%2Fo&etcetcetc...'); ***

But it complains about "Opportunity" not being defined. Can someone help..?

ADDED: Button is located on a standard Opportunity page layout.

ADDED: New code (minus the ELSE section)...



var t = { ! ISBLANK( Opportunity.Amount ) };
alert(t + ' ' + typeof t);

if( !Opportunity.Company_Is_NEXT_STEP__c  ) {
alert ("NEXT STEP checkbox must be selected (just an example error)");

} else {
*****  else routine - works fine *****

RESULT OF THE above is (verbatim): "Unexpected token !"

Attribution to: AMM

Possible Suggestion/Solution #1

Check what does this return for you:

var value = '{!Opportunity.Amount}';
var blankTest = {!ISBLANK(Opportunity.Amount)};
alert (value + "\r\n" + typeof blankTest + ' ' + blankTest);

(note that you had syntax error, ISBLANK should be within the {!...})

RE: "Unexpected token !"

No, you can't have code like { ! ... and expect it to work! Maybe you did it for nice formatting but there's no way it will work... Curly brace, immediately followed by exclamation mark....

enter image description here

Attribution to: eyescream
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content