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
ethan huntethan hunt 

Disabling button on specified condition

Hi,

 

I have a custom list button on Opportunity object , I want when Stage field in Oppertunity changes to Prospecting the custom buuton wil get diabled and when it chnage to some other value the button will get enabled.

 

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Opportunity)};
var status = "{!Opportunity.StageName}";
if(status=='Prospecting')
{
alert ('Completed');
}
else{
this.disabled = true;
}

 

Regards

Subramani_SFDCSubramani_SFDC

Hi

    Try like this

 

 <apex:commandButton action ="{! method name}" value ="" rendered ="{f(status=='Prospecting'),false, true)} " />

 Did this post answers your question if so please mark it as solved

liron169liron169

Hello,

 

in case the button is in standart SF layout, than it
is quite problem to changed the button property.

Simple way will be to add validation in the JS.

if(status=='Prospecting')
{
    alert('This button is not acceissble when status is Prospecting');
}

sandeep@Salesforcesandeep@Salesforce

<apex:commandButton action ="{! method name}" value ="" disabled="{!if(status=='Prospecting'),true,false)} " />

ethan huntethan hunt

Hi,

 

Thanks for your reply. I am trying to add this button in Opportunity . Could you please help me in this as i am trying to do the following 

 

<apex:page standardController="Opportunity">
<apex:form >
<apex:detail subject="{!Opportunity.Id}" relatedList="true" title="false"/>
<apex:pageBlock >
<apex:commandButton onclick="alert()" value="CustomSave" rendered="{if(status=='Prospecting'),false, true)} " />


<script>
function alert()
{
var status = {!Opportunity.StageName}.value;
if(status=='Prospecting')
{
alert('This button is not acceissble when status is Prospecting');
}
}
</script>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Regards