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
Rahul GoyalRahul Goyal 

On click javascript

Hi All,

we need to display a custom button for some of the user only not all the users. what is the best way to achieve this functionality ?

I am trying to create a button for the on click javascript function, if the current user is xxx that clicking on button will display error, but seems this is not working. could some one please modify the code and update me.

===========
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")};
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")};

User Usr = new User();
Usr = [SELECT Phone, Id FROM User WHERE Id = : UserInfo.getUserId()];



if(Usr.ID= '005d0000002yJI4') {
    alert("You cannot use this button on this account.");
} else {
    window.open("https://www.google.co.in/?gfe_rd=cr&ei=TDrpVZXNDdHCuASCg5xA&gws_rd=ssl");
}
==============================
Regards,
Rahul
Pritam ShekhawatPritam Shekhawat
Hello Rahul,
                 Take a look this How to make custom button visible for particular users? (https://help.salesforce.com/apex/HTViewSolution?id=000188475&language=en_US)  Let me know if phasing any issue.

Thanks,
Pritam Shekhawat
Vignesh P 6Vignesh P 6
Hi Rahul Goyal,

        I hope, this will satisfy your expectation.

=================
{!REQUIRESCRIPT('/soap/ajax/29.0/connection.js')}

result = sforce.connection.query("SELECT Id FROM User WHERE Id = '{!$User.Id}'");

records = result.getArray("records");

if(records[0].Id == '005d0000002yJI4') {
    alert("You cannot use this button on this account.");
} else {
    window.open("https://www.google.co.in/?gfe_rd=cr&ei=TDrpVZXNDdHCuASCg5xA&gws_rd=ssl");
}

=================

Thanks,

Vignesh P
Rahul GoyalRahul Goyal
Thanks for the inputs..

Below code is working and it is showing error as expected for the specific user : 
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")}

var currentUser = sforce.connection.getUserInfo();
//alert('the profile Id is '+ currentUser.userId);

var list = "{!$Setup.Users__c.getInstance.getValues()}";
alert(list);


if("{!User.FirstName}" == "Rahul")
 {
    alert("You cannot use this button on this account.");
} else {
    window.open("https://www.google.co.in/?gfe_rd=cr&ei=TDrpVZXNDdHCuASCg5xA&gws_rd=ssl");
}


===========================

The only problem is that I need to provide the FirstName in the code for the user. If there are group of users How can I modify this code instead of providing first name or last name in the above code. Is there any way we can use custom setting?

Any help is appreciated....

Regards,
Rahul