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
JCSJCSJCSJCS 

Javascript - IF User has "permissions"?

I have a List View Button that runs javascript to change the contents of a field.  Basically, it is a bulk approval process - our salesmanager can run a list, check off a bunch of deals, then click the button to "Approve" a process (which is indicated by a specific field being updated to "APPROVED.")
 
I only want him to be able to run this button and have added a USER CUSTOM FIELD called APPROVE_DATA.  How can I incorporate an IF statement in the javascript to first check if the logged in USER has APPROVE_DATA = TRUE before running the button.  If APPROVE_DATA = FALSE, I would kick out an error.
 
Thanks - jcsjcs
 
 
jpizzalajpizzala
You can access the custom field by using this in your Javascript:

{!$User.APPROVE_DATA__c}

So something like the following may work for you:

Code:
var canApprove = "{!$User.APPROVE_DATA__c}";
if (canApprove == true) {
  // run the button process
} else {
  // display error
}
Hope this helps
 

JCSJCSJCSJCS
Thanks for the help - worked like a charm!