function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TsvetyTsvety 

Onclick javascript button works for some users and doesn't for others

Hi,

This might be something simple, but I cannot figure it out.
The below button works for some users and doesn't for others.

Here is the code:


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

if({!ts2__Offer__c.Estimated_Gross_Margin__c}<40)

alert("The margin for this Resource is less than 40%. An automatic request for approval will be sent to the executive team");} 

else{ alert ("Completed"); 
}


Here is the error I get:

User-added image
 
Best Answer chosen by Tsvety
Daniel BallingerDaniel Ballinger
Do all users have access to the custom formula field? I'm guessing that if they don't have permissions to see that field it will merge as blank.

All Answers

Daniel BallingerDaniel Ballinger
What value does {!ts2__Offer__c.Estimated_Gross_Margin__c} contain?

If it is null or the empty string for some records then the javascript is likely to be something like the following, which would explain the JavaScript error.
if(<40) { 
    alert("The margin for this Resource is less than 40%. An automatic request for approval will be sent to the executive team");} 
else {
    alert ("Completed"); 
}

You may need to add additional checks for empty values first.
TsvetyTsvety
Thanks for taking the time to reply.
The 
{!ts2__Offer__c.Estimated_Gross_Margin__c} is a Formula (Percent) field.

Please note that the button works for some users and on exactly the same record, it doesn't work for others.
 
Daniel BallingerDaniel Ballinger
Do all users have access to the custom formula field? I'm guessing that if they don't have permissions to see that field it will merge as blank.
This was selected as the best answer
TsvetyTsvety
Yes, they can see the field.
TsvetyTsvety
Hi Daniel,
I doublechecked and even though the field was visible to the user, there were some restrictions in regards to the field level security. I changed it so now the button works!
Thanks for your help!
Daniel BallingerDaniel Ballinger
Can you impersonate (Log in as) one of the affected users and do a view source on the page when the error occurs? I'm fairly confident from the error message that it is merging as an empty value. It would certainly explain the error message.

Other than that, are they using a different browser version by chance? The screenshot you supplied makes me think it is a version of Chrome.