Find your content:

Search form

You are here

Button Validation Logic

 
Share

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.

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

if(ISBLANK({!Opportunity.Amount})) {
alert ("Opportunity Amount cannot be blank");
} else {
*** would be normal result here ****
*** such as:    window.open('/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)...

{!REQUIRESCRIPT("/apex/dsfs__DocuSign_JavaScript")}

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}

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 https://salesforce.stackexchange.com/questions/4497

My Block Status

My Block Content