1

I know next to nothing about javascript so don't beat me up too much if this is utter garbage, but here is my attempt at a somewhat simple button that looks at 2 values and kicks a flow off or surfaces an error message depending on the values:

{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/34.0/apex.js")} 
if(({!Account.OwnerId} == '00530000006Vg2N')) || 
({!Account.Inactive_Owner__c}));{ 
location.replace('/flow/Inside_Account_Update_Me'); 
} 
else {alert("This Account is either not owned by Debbie or your role doesn't 
allow you to move these accounts. Reach out to Sales Ops if you feel this is 
in error"); 
}

The intention is for a user to click this button to assign the account to themselves. The code should look to see if it's owned by user a ('00530000006Vg2N') or if the user is inactive (checkbox where true = inactive). If either of those are true it should run the flow, if both are false it should surface the error message.

Any clues would be much appreciated.

Thanks, Mark

2

This is more likely to work:

{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/34.0/apex.js")} 
if ('{!Account.OwnerId}' == '00530000006Vg2N' || {!Account.Inactive_Owner__c}) {
    location.replace('/flow/Inside_Account_Update_Me'); 
} 
else {
    alert("This Account is either not owned by Debbie or your role doesn't allow you to move these accounts. Reach out to Sales Ops if you feel this is in error"); 
}

You have to imagine what the code will look like when the {! } tokens have been replaced. Pasting an exact copy into http://jshint.com/ replacing those tokens with typical values can also help.

You will see any JavaScript errors in your browser's Developer Tools console so have that open as you develop/test.

(Also bear in mind that JavacrScript buttons don't work in Lightning Experience so to future proof you might consider other approaches.)

| improve this answer | |
2

It is far easier to evaluate the conditions entirely in the formula/merge syntax, because doing so helps catch errors, is marginally less case-sensitive than using JavaScript directly, and avoids potential injection attacks if you screw something up (e.g. not JSENCODEing a string that can be updated by the user).

Here's the rewrite using a formula evaluation:

{!REQUIRESCRIPT("/soap/ajax/34.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/34.0/apex.js")} 
if( {!OR(Account.OwnerId="00530000006Vg2N",Account.Inactive_Owner__c)} ) { 
  location.replace('/flow/Inside_Account_Update_Me'); 
} else {
  alert("This Account is either not owned by Debbie or your role doesn't 

allow you to move these accounts. Reach out to Sales Ops if you feel this is in error"); }

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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