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
mohan.smmohan.sm 

Enable/Disable button for particular picklist values

Hi Everyone,

I have a Button(Send__c) and a pick list field(Status__c) with values New, Modified, Submitted and Synced.

1.On click of Button the Status should be set to submitted.
2. Button should be only active if the status is New or Modified else it should be inactive/grayed out.

Can someone pls help me with this requirement?

Thanks!!
Sudheera LakmalSudheera Lakmal
 Hello,

You need to create the Custom button as Detail Page Button with Execute JavaScript behavior, and in the onClick section add the logic to change the status to Submitted. Below is the code segment;
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

// identify the record
var yourObjectName = new sforce.SObject("Name of your Object");
yourObjectName.id = "{!yourObject.Id}";

yourObjectName.Status__c = 'Submitted';

// save the change
sforce.connection.update([yourObjectName]);

//refresh the page
window.location.reload();

 
 
As I know there is no way to inactive or grayed out the custom buttons in page layouts. Hence you need to create two page layouts here, 
  • Page layout 1 – for New and Modified statuses à You can insert your custom button in this page layout
  • Page layout 2 – for Submitted and Synced status à you are not going to add your custom in this page layout 
Then create two Record Types for respective Page Layouts as you need to switch between page layouts.
  • Record Type 1 à for Page Layout 1
  • Record Type 2 à for Page Layout 2 
Finally, create a workflow rule to change the Record Type. Because in order to click the button you should be in Page Layout 1, after clicking the button you should be switched to Page Layout 2.
 
Please let me know if you need further assistance. Meanwhile please note that this is my approach, others may have different approaches.
sandeep@Salesforcesandeep@Salesforce
There is another way: 
1. Please create a formulafield and keep return type a text.
2. Now you can write your logic to show a button image if status is New otherwise put NULL so that nothing would be visible. or you can show image of grayed button. 
3. you can embade a url on clicking on this formula field so that a new VF page can be hit you can update status and it will get back you on same page. 
Here is sample code
IF((your condition logic) ,HYPERLINK("/apex/yournewVFpage?id="&Id,IMAGE("/resource/Buttonimage", "ButtonName"),"_self"),NULL)

Please let me know in case of any further query. 
Thanks
Sandeep Singhal
http://www.codespokes.com/