Use Cases for Validation Rules Using Functions

Use Cases for Validation Rules Using Functions

Make detailed description mandatory if specific terms are entered in the field
Zylker Tech manufactures electronic assemblies and similar other products. Their manufactured items are outsourced for quality check to a third-party service provider. The assessment results are shared with the production managers through the assessment and evaluation report. Often times it has happened that important fields in the form are either left blank or the description given is unclear. This lack of information results in to-and-fro communication that causes delay in further processing and also poses problem when they plan on implementing the details to their process improvization plans. In order to arrest such issues in the future reports, the production managers decide to put a check that prompts the users to enter detailed description whenever they enter certain terms in the fields.

Here's the validation rule that needs to be configured for the desired result: 
Validate the field to throw error if the user enters any of these values - miscellaneous, not specific, recommended, critical, nondescript. The alert message will be: You have used term(s) that need to be described more specifically. Please enter a comprehensive description.  

Below is the snippet of the function: 
/* 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'}; */
field = entityMap.get("field_api_name");
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(condition) {
//response.put('status','error');
//response.put('message', '<your message(100 characters)>');
//} else {
/* If there are no errors found during validation, set the status as shown below: */
response.put('status','success');
//}

/* ---------------------------------------------------------------------------------------------- */
return response.toString();
Function for the above rule:
 if(Description.contains("miscellaneous") || Description.contains("recommended") || Description.contains("critical") || Description.contains("not specific") || 
Description.contains("nondescript")) { 
  response.put('status','error'); 
  response.put('message', 'You have used term(s) that need to be described more specifically. Please enter a more comprehensive description.'); 
 } else { 

Validate the pattern of the mailing zip code for each country

Validate that the zip code entered in the mailing address follows a particular format for the following countries:

*Add the below codes to the snippet where indicated.

1. Country is Bangladesh the zip code should be in 9999 format. 
condition: zipCode.matches("([0-9]{4})" ) == false
2. Country is Canada the zip code should follow this format A9A 9A9.
condition: zipCode.matches("([A-Z]{1}[0-9]{1}[A-Z]{1}[0-9]{1}[A-Z]{1}[0-9]{1})") == false
3. Country is Jamaica the zip code should begin with alphabets followed by number, in this format AAAAA99.
condition: zipCode.matches("([A-Z]{5}[0-9]{2})") == false
4. Country is Latvia the zip code should have alpha character, numeral and hyphen in this order, AA-9999.
 condition: zipCode.matches("([A-Z]{2}-[0-9]{4})") == false

Validate the Regex expression of identification data such as IBAN 

Some data follow a specific format and expression that changes with respect to individual country. Data like IBAN (International Bank Account Number) follows a particular structure that includes the country code followed with the account number. Not only that, the number of characters in the account number varies from every country. 

*Add the below codes to the snippet where indicated.

1. Country is Albania the IBAN number should begin with the country code AL followed with account number in 28 numeric characters.  
condition: IBANNumber.matches("(^(AL)[0-9]{28})") == false
2. Country is Belgium the country code should be BL followed with account number in 16 numeric characters. 
condition: IBANNumber.matches("(^(BL)[0-9]{16})") == false
3. Country is Germany the country code should be DE followed with 22 numeric characters for account number. 
condition: IBANNumber.matches("(^(DE)[0-9]{22})") == false

Validate the format in which the ISSN number should be entered

ISSN (International Standard Serial Number) is a unique, eight digit serial number that identifies the publication code. The number is represented in a specific pattern like: two four-digit numbers divided by hyphen (0378-5955). While searching for an article using the ISSN code, the number must be entered in the given format. So you can validate the format of the ISSN field using function.

*Add the below code to the snippet where indicated.
condition: ISSNNumber.matches("([0-9]{4}-[0-9]{4})") == false

Validate the phone number has international format

In personal information, the contact numbers entered by the customers should follow the international format. So, validate that the phone number field stating, the number must start with + followed by the country code and national number. You can enter the country codes in the function.

*Add the below codes to the snippet where indicated.

1. The UK based number should be in this format +44-20-999999999.
condition:   phoneNumber.matches("(^(\+44-20)-[0-9]{9})") == false
2. The US based number should be in this format +1-999-999999999.
condition:   phoneNumber.matches("(^(\+1)-[0-9]{3}-[0-9]{9})") == false
3. The Netherlands number should be like this +31-99-999999999.
condition:   phoneNumber.matches("(^(\+31)-[0-9]{2}-[0-9]{9})") == false

Restrict the reps from entering any past dates as closing date

A rep should be restricted from entering a past date in the closing dates. For example, if the sales person edits the deal closing date then he should be prevented from entering any past date. They should update the field with future date only.

*Add the below code in the snippet where indicated.
condition: days360(today, closingDate.toDate()) > 0


    • Related Articles

    • 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 ...
    • Working with Validation Rules

      Creating and keeping high-quality data is difficult, but it's even harder to identify and fix a dataset full of mistakes. Faulty CRM data can lead to negative consequences for a company, including impeding operations, generating unreliable reports, ...
    • Associate Functions

      Zoho CRM Functions help you to update the data in related CRM modules or third-party applications by executing simple program scripts. When a record matches the workflow criteria, workflow engine automatically triggers the function and update the CRM ...
    • Working with Cases

      In the world of Internet, online Customer Support has become an integral part of the organizations' business process. Customer Support is an important activity in all types of product and service industries. In general, case trouble tickets are used ...
    • Configuring Workflow Rules

      Workflow Rules in Zoho CRM, are a set of actions (email notifications, tasks and field updates) that are executed when certain specified conditions are met. These rules automate the process of sending email notifications, assigning tasks and updating ...