i have a custom button on Quote detail page, on click of this button i am calling a function through javascript.

On load of this Quote detail page, If the Quote status is 'Accepted' then i need to disable this button. if the Quote status is something else then i need to enable this button. On click of the button(when enable) i want to change the Quote status to 'Accepted'.

i don't know how to achieve this. i tried doing it with javascript but it doesn't work for me.

below is my javascript code of the custom button.

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}

if("{!Quote.Status}" != "Accepted"){
var QuoteId = "{!Quote.Id}";
alert(QuoteId);
sforce.apex.execute("GenerateXMLOnQuoteAccept","generateXML",{QId:QuoteId});
alert('done');
}

button setting: Behavior: Execute Javascript
Content Source: Onclick Javascript

There is no way to disable button but you can extend your JavaScript code to notify user like:

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
if("{!Quote.Status}" != "Accepted"){
var QuoteId = "{!Quote.Id}";
alert(QuoteId);
sforce.apex.execute("GenerateXMLOnQuoteAccept","generateXML",{QId:QuoteId});
alert('done');
}
else
{
alert('Error:Quote is already accepted');
}
  • any work around? – Ritz Arlekar Oct 4 '16 at 9:24
  • 1
    You can go for a solution based on record type and page layouts. There would be two layouts one with button and one without button. On first click of button you can change record type that will send user to replica record type which do not contain that button. – Mukesh Verma Oct 4 '16 at 9:30

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.