Drawloop Button: Error when a field has no value

Problem:
You would like a User to only be able to run a DDP from an Opportunity record if the Type field has a value, otherwise you would like the User to receive an alert stating the Type field must be entered first.

Solution:
Using JavaScript we will create a custom button that will evaluate the field, ensure it meets the criteria and if not, present the User with an error.

Steps:
1. In Salesforce, navigate to an Opportunity record.
2. Click the arrow on the right-hand side of the page.
3. Select View Object
4. In the left-hand menu, select ‘Buttons, Links, and Actions’
5. Click the ‘New Button or Link’ button
6. Provide the button with a Label. The value provided will be cloned in the Name field as well.
7. Set the Display Type to ‘Detail Page Button’.
8. Set the Behavior field to ‘Execute JavaScript’. The Content Source field will change to ‘OnClick Javascript’
9. Copy the code below:

{!REQUIRESCRIPT(“/soap/ajax/26.0/connection.js”)} if (‘{!Opportunity.Type}’ == ” )     alert(‘You cannot generate a quote unless Type has a value.’);else    window.location.href = ‘/apex/loop__looplus?eid={!Opportunity.Id}&accountId={!Opportunity.AccountId}&sessionId={!$Api.Session_ID}’;

10. Click ‘Check Syntax’ to ensure there are no errors.
11. Click ‘Save’.

Once the newly created custom button is added to the page layout you’re all set!

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top