Validate script examples

Example 1

This example adds a Validate Script, which checks the validity of the Opportunity Certainty field. If the field value is set to less than 25%, it expects the Opportunity Priority to be set to Low. If this is not the case, a validation error message is displayed to the user.

You must attach Validate Scripts in the field you want the valid error to show up against.
  1. Click <My Profile> | Administration | Customization.
  2. Select Opportunity Progress from Secondary Entities.
  3. Click the Screens tab.
  4. Click Opportunity Status Box.
  5. Select OpportunityProgress: Priority in the Screen Contents panel.
  6. Type the following script in Validate Script.
    Copy
    if (Values('oppo_certainty')<25 && Values('oppo_priority')!='Low')
        {
            Valid=false;
            ErrorStr="please set the priority to Low";
        }
  7. Click Update and then click Save.
  8. Add a new opportunity, set the Priority to 20 and click Save. A validation error is displayed to the user with the error you specified.

Example 2

You can add a Validate Script, which validates that every customer who is buying a License is assigned a Customer Reference ID that begins with the letter 'L'. Otherwise it displays an error message.

  1. Click <My Profile> | Administration | Customization | Primary Entities | Opportunity, and click the Screens tab.
  2. Click Opportunity Detail Screen.
  3. Select Opportunity : Customer Ref.
  4. Enter the following script in ValidateScript:
    Copy
    custref=Values('oppo_customerref')+'';
    if ((Values('oppo_type')=='License') && (custref.charAt(0)!='L'))
        {
            ErrorStr='!'+custref+'The customer reference must begin with L';
            Valid=false;
        }
  5. Click Update and then click Save.
  6. Create a new opportunity, select License from Type, enter a customer reference number beginning with any letter except L.
  7. Click Save. The error displayed indicates that this type of opportunity must be assigned a customer reference beginning with L.