Zoho CRM Creating Validation Rules Using Functions

Zoho CRM Creating Validation Rules Using Functions

By using function you can create a validation rule where the value entered by the user needs to be verified outside the CRM database. You can even validate the fields like phone numbers, zip code and so on for a particular pattern by mentioning the appropriate pattern in the function. For example, you can write a function to validate the account number field, such that it accept values only if they adhere to this pattern: xxx-999-x00. As account numbers are confidential and most likely be stored in a government database or bank repository, you must allow CRM to verify the pattern in those third-party databases and throw an alert whenever there is a mismatch.

Scenario
You are in a retail business and use third-party logistics to handle door-to-door deliveries and bulk shipments. Every shipment is tracked using a 10-digit reference number that is stored in the latter's database. Whenever a sales rep enters an erroneous reference number in CRM, you want to prevent the record to be saved so as to avoid unnecessary issues and delays in tracking the shipments during customer enquiries. You can validate the "reference number" field using function, such that the value will be verified at the logistic company's database for exact match. The record will then be saved only if the rep enters a 10-digit value in the appropriate format (xxx-9999999999) mentioned in the validation rule, otherwise an error be thrown showing invalid data. 



/* The snippet below shows you how to get a list of fields, their values from a MAP object. The fields’ values can be obtained from the same MAP object. */
entityMap = crmAPIRequest.toMap().get("record");
/* The example below demonstrates how a field’s value (email) can be obtained from a MAP object. Here, entityMap - Map Object, Email - Field's API name
Sample entityMap= {'Email': 'xxx@xxx.com', 'Last_Name': 'xxx'}; */
referenceField= entityMap.get("Reference_Number"); // Reference_Number is the API name for "Reference number" field.
response = Map();
/* ---------------------------------------------------------------------------------------------- */
Start writing your code here to perform the necessary field validation *
/* ---------------------------------------------------------------------------------------------- */
/* If the code identifies a validation error, set the status and alert message as shown below: */
if(referenceField.matches("[A-Z]{3}-[0-9]{10}")) {
      response.put('status','error');
      response.put('message', 'Invalid Reference Number');
} else {
/* If there are no errors found during validation, set the status as shown below: */
      response.put('status','success');
}
/* ---------------------------------------------------------------------------------------------- */
return response.toString();
Note
  1. You can change the criteria-based validation rule of the existing records into function-based validation rule by writing a function that facilitates the validation rule.
  2. The total number of validation rules that can be created depends on the subscribed edition. Out of the total number of rules/modules, you can create 3 validation rules using functions in the Enterprise edition, and 5 rules using functions in the Ultimate edition. To know the total number of rules for each edition, check the Feature Availability page.
  3. Only the fields that are supported in the criteria-based validation rule will be available in the function-based rule too.
  4. To avoid failure of the function, its advisable to give empty value checks as sometimes the fields are blank (fields without value). 
  5. Return value from the function should be as mentioned in the sample code. Any value other than the mentioned return value will be considered as an error.
  6. The field values will be available inside the function in API format only. To access the values you can use the field API name.
  7. Validation execution will be applicable in Zoho CRM mobile app too. However, you will not be able to create a rule from the mobile app.
  8. In case the function fails to execute, you will be alerted to check for the following possible reasons:
    1. Logical errors in your code.
    2. Execution timed-out causing function failure.
    3. If the issue persists, please contact support@zohocrm.com for assistance.

To create validation rule using functions
  1. Go to Setup > Customization > Modules and Fields.
  2. Hover on the Module, click the More icon and select Set Validation rules.
  3. Under Validation Rule tab, click New Validation Rule.
  4. In Create Validation Rule page, under Choose field to validate select a field from the drop-down list.
  5. In Choose Validation type, check Validate using function.
  6. Click Next.

  7. In Configure Function page, do either of the following:
    1. Click Functions > Choose a function Configure > Save.
    2. Click Create your own > Enter the function > Save.
  8. Click Save, to save the validation rule. 
Note
The functions that are created under  CRM Fundamentals  (in Functions Tab) can be associated with validation rule. 
  1. Go to Setup > Developer Space > Function > Create New Functions.
  2. In Choose a place, select CRM Fundamentals from the drop-down list.

    • Related Articles

    • Zoho CRM Creating Email Templates

      Communicating with customers is an important activity in any business scenario. Zoho CRM provides Email Templates to send one message to multiple recipients. Email templates can be also be used to send Mass Emails to leads/contacts or send Email ...
    • Zoho CRM Adding Layouts Rules

      Layout Rules in Zoho CRM offer an interface for you to seamlessly manage dependency between fields in a layout. Your sales data are often inter-dependant. Consider the following examples. In a real estate company, the particulars required from a ...
    • Zoho CRM Working with Validation Rules

      One of the most challenging tasks in CRM system is ensuring the validity of data in it. A poorly maintained set of data can cost a company in more ways than one - your activities are slowed down, you will have inaccurate reports and it's plain ...
    • Zoho Recruit Working with Custom Functions

      In today's fast-paced recruitment landscape, organizations often grapple with manual and time-consuming tasks that hinder efficiency and productivity. Tracking candidates, managing interview schedules, and maintaining data accuracy can become ...
    • Zoho CRM Creating Kanban Views

      Kanban view is a card-based view that displays the data in an organized manner for better comprehension. For example, you can segregate the leads based on their status or categorize the sales depending on different stages. This sort of information ...