Drawloop Button: Error when a field has no value


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.



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.


Get the button code here: Error based on field criteria



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. Insert code:

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!



Further Customization:

Change the Field:
Replace the {!Opportunity.Type} merge field tag with the merge tag for the field you would like to evaluate.

Change the Alert Message:
Replace You cannot generate a document unless Type has a value with the new alert message.