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
Rung41Rung41 

Onclick Javascript Help

I'm trying to implement an OnClick Javacript Button to only allow users with a certain profile to use the button. However, I keep getting the following error. Unterminated String constant.

Any help would be appreciated.
if("{!User.ProfileId}" = "00e30000000tnOY")
{ 
alert("Nice try, think again."); 
} 
else{ 
window.location = "/006/e?retURL={!Account.Id} 
&accid={!Account.Id} 
&RecordType=012a0000001ZSiy 
&ent=Opportunity&opp3="Opportunity" 
&opp11="New" 
&opp9={!TODAY()+30}"; 
}



 
Lalit Mistry 21Lalit Mistry 21
Try with below script. That should help you out. Also, note that I have used profile name instead of Id as better option to prevent any migration issue.
var profileName = "{!$Profile.Name}";
if( profileName == "System Administrator")
{ 
alert("Nice try, think again."); 
} 
else{ 
window.location = '/006/e?retURL={!Account.Id}&accid={!Account.Id}&RecordType=012a0000001ZSiy&ent=Opportunity&opp3=Opportunity&opp11=New&opp9={!TODAY()+30}'; 
}

If it resolves your problem, mark this as an answer for benefit of others.
AKumAKum
Hey Rung41,
It seems that your else block is creating issue 
if("{!User.ProfileId}" == "Put Wrong Profile Id To Check Else or Correct to Check if Block"){ 
alert("Nice try, think again."); 
}
else{
location.reload(true);
}

Try above code .
Thanks !