1

I have a custom button on Contact Screen and a Contact Sync Status Picklist with values New, Modified, Submitted and Activated.

On click of button Status will be set to submitted which is done via javascript on button. Following is the existing code on the button. Now I want to disable this button when the status is set to Activated.

Activated status will be set by external system through an interface. How can it be done with javascript on the button.

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var p = new sforce.SObject('Contact'); 
p.id = "{!Contact.Id}"; 
p.Contact_Sync_Status__c = "Submitted"; 
result = sforce.connection.update([p]); 
location.reload(true);

Thanks!

3
  • Welcome to salesforce.stackexchange Mohan. You've only told us what you're trying to do but you haven't asked us any question. Mind updating your post to have more details, an actual question and how you're stuck with doing this ? May 20, 2016 at 19:33
  • Hi Samuel/Todd, That is an javascript button when we click on that button status will set to submitted. {!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} var p = new sforce.SObject('Contact'); p.id = "{!Contact.Id}"; p.Contact_Sync_Status__c = "Submitted"; result = sforce.connection.update([p]); location.reload(true); I need to disable/deactivate the button when the status picklist value changes to Activated.. Let me know for any further questions. Thanks!
    – Mohan
    May 20, 2016 at 20:56
  • Mohan - use the edit link to change your question -- comments are too hard for people to read when code is involved
    – cropredy
    May 20, 2016 at 21:52

2 Answers 2

3

As Samuel says in his comment, it's difficult to help without any context as to how your stuck (or even what type of button this is and what it does), but, if this button is an onclick Javascript button, you could add a condition to the button to prevent its use if the status is activated:

var status = "{!Contact.Status__c}";

if(status == "Activated"){
    alert("[Your Error Message Here]");
}
else{
    //do some logic here
}
1
  • Hi Samuel/Todd, That is an javascript button when we click on that button status will set to submitted. {!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} var p = new sforce.SObject('Contact'); p.id = "{!Contact.Id}"; p.Contact_Sync_Status__c = "Submitted"; result = sforce.connection.update([p]); location.reload(true); I need to disable/deactivate the button when the status picklist value changes to Activated.. Let me know for any further questions. Thanks!
    – Mohan
    May 20, 2016 at 20:45
0

We don't have the provision to disable/hide custom buttons in page layouts based on some conditions(picklist, lookup, etc.,) yet.

For a workaround(to hide button), you can create two pagelayouts(one with button and other without button) and two recordtypes(one assigned to pagelayout with button and other without). Have a workflow/process builder field update to change the recordtype to the one which is associated to page layout without button once status picklist changes.

Hope it helps.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .