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
Gdickens3Gdickens3 

I have a custom java script button that I need to modify to look at the user; is that possible?

My code below is the one I'd like to modify - it works fine for looking at fields on the account, but I am trying to use something similar but looking at the user clicking the button.  I gett an error using userid or username.

Current Code (working):
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")};
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")};
if('{!Account.RecordType}' == "Unitrends - End User" || '{!Account.Account_Status__c}'=="Prospect")
alert ("Cases should be created from the Asset for current customers or from an Opportunity for Prospects");
else
open('500/e?retURL=%2F500%2Fo&RecordType=012300000000Xth&ent=Case');

NEW CODE for USER:
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}; 
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}; 
if('{!User.Id}'= "00540000001sVhY" )
alert ("Cases should be created from the Asset for current customers or from an Opportunity for Prospects"); 
else 
open('500/e?retURL=%2F500%2Fo&RecordType=012f0000000D63a&ent=Case');
lakslaks
Hi,

Do try using {!$User.Id}

Regards,
Lakshmi.
James LoghryJames Loghry

Also:

  1. Be sure to use == (comparison) instead of = (assignment) operator. 
  2. Hard coding Ids is a horrible Id, if you can grab it from a custom setting or configure it so that you aren't hard coding ids, you'll have a more robust solution.