You need to sign in to do that
Don't have an account?
Can I disable the function of a custom button with an IF/conditional statement?
Hi All,
I have a custom 'create case' button in opportunities that creates a new case from an opportunity, passing some of the opportunity field data across into the case as it does so.
The button code looks like this:
/500/e?retURL=%2F500%2Fo
&cas4_lkid={!Account.Id}
&cas4={!Account.Name}
&CF00N30000009y6pH_lkid={!Opportunity.Id}
&CF00N30000009y6pH={!Opportunity.Name}
&cas3_lkid={! NULLVALUE (Case.ContactId, Contact.Id )}
&cas3={! NULLVALUE (Case.Contact, Contact.Name )}
&cas5={!Opportunity.Type}
&cas14={!Opportunity.Name}
&cas15={!Opportunity.Requirement__c}
&retURL=/{!Opportunity.Id}
&saveURL=/{!Opportunity.Id}
Am I able to disable the function of this custom button if the opportunity stage IS NOT 'closed won'? Ideally I'd like an alert pop-up box to appear if the 'create case' button is clicked when the opportunity IS NOT 'closed won' but for the button to work as intended and create the new case if the opportunity IS 'closed won'.
Any help would be really appreciated.
Thanks to all.
Steve
This should work for you...
if ("{!Opportunity.StageName}" == 'Closed Won') { location.href = "/500/e?retURL=%2F500%2Fo&cas4_lkid={!Account.Id}&cas4={!Account.Name}&CF00N30000009y6pH_lkid={!Opportunity.Id}&CF00N30000009y6pH={!Opportunity.Name}&cas3_lkid={! NULLVALUE (Case.ContactId, Contact.Id )}&cas3={! NULLVALUE (Case.Contact, Contact.Name )}&cas5={!Opportunity.Type}&cas14={!Opportunity.Name}retURL=/{!Opportunity.Id}&saveURL=/{!Opportunity.Id}";
} else { alert('only closed won opps can be ...'); }
Thanks
Rakesh Aggarwal
www.rakeshaggarwal.com
All Answers
Additionally, you might want to have a validation rule on the case object to limit a user from creating a case from scratch (i.e. from the cases tab), related to an opportunity that has a non- closed/won stage. Maybe you already have this covered.
Cheers!
Let us know the outcome.
I dont think there is a need for record types here.
Configure the custom button the following way:
1.behaviour = execute javascript
2.Content source = onclick Javascript
paste the following into the code editor:
instead of the 'its fine' alert - do you logic.
etc.
if this solves the issue for you, please mark it as resolved
Hi Noam,
Thanks for your help with this ... I found some similar JS code for this type of validation, but not being too conversant with JS wasn't sure how my original URL based code would appear as JS.
Are you able to help with this? What would the JS code look like for the button to make the 'closed won' / not 'closed won' check, and then pass the required opportunity fields across to the new case?
If you can give me a couple of pointers, I should be able to work it out.
Many thanks again.
Steve
This should work for you...
if ("{!Opportunity.StageName}" == 'Closed Won') { location.href = "/500/e?retURL=%2F500%2Fo&cas4_lkid={!Account.Id}&cas4={!Account.Name}&CF00N30000009y6pH_lkid={!Opportunity.Id}&CF00N30000009y6pH={!Opportunity.Name}&cas3_lkid={! NULLVALUE (Case.ContactId, Contact.Id )}&cas3={! NULLVALUE (Case.Contact, Contact.Name )}&cas5={!Opportunity.Type}&cas14={!Opportunity.Name}retURL=/{!Opportunity.Id}&saveURL=/{!Opportunity.Id}";
} else { alert('only closed won opps can be ...'); }
Thanks
Rakesh Aggarwal
www.rakeshaggarwal.com
Thanks Rakesh ... with the exception of a missing '&' symbol, your solution was perfect.
Much appreciated!
Regards
Steve