+ Start a Discussion
MLamb2005MLamb2005 

Problem with On-Click JavaScript... help please...

Hi all,

 
I'm trying to add the following check to an on-click piece of JavaScript in a button (to restrict access to the button).  My condition in the "IF" isn't working right, anyone see why?

 

if({!User.ProfileId} <> '00e00000006ojvr'){ alert("This feature is currently only available to Administrators."); } else{ ** Do stuff** }

 


 

Best Answer chosen by Admin (Salesforce Developers) 
CaptainObviousCaptainObvious

Try:

 

if('{!$User.ProfileId}' != '00e00000006ojvr') { alert("This feature is currently only available to Administrators."); } else{ ** Do stuff** }

 

All Answers

CaptainObviousCaptainObvious

Try:

 

if('{!$User.ProfileId}' != '00e00000006ojvr') { alert("This feature is currently only available to Administrators."); } else{ ** Do stuff** }

 

This was selected as the best answer
AlsoDougAlsoDoug

I don't know your actual requirements but if it's a Visual Force page you could also use

 

rendered="{!IF( $User.profileId = '00e00000006ojvr', true, false)}"

 

That way the button is not even displayed.

MLamb2005MLamb2005
Works perfect, thanks!