Use Cases Validation Rules Using Functions | Online Help - Zoho CRM

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': '', '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('message', '<your message(100 characters)>');
//} else {
/* If there are no errors found during validation, set the status as shown below: */

/* ---------------------------------------------------------------------------------------------- */
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('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

    Zoho CRM Training Programs

    Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

    Zoho CRM Training
      Redefine the way you work
      with Zoho Workplace

        Zoho DataPrep Personalized Demo

        If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

        Zoho CRM Training

          Create, share, and deliver

          beautiful slides from anywhere.

          Get Started Now

            Zoho Sign now offers specialized one-on-one training for both administrators and developers.

            BOOK A SESSION

                                    You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.

                                        Manage your brands on social media

                                          Zoho Desk Resources

                                          • Desk Community Learning Series

                                          • Digest

                                          • Functions

                                          • Meetups

                                          • Kbase

                                          • Resources

                                          • Glossary

                                          • Desk Marketplace

                                          • MVP Corner

                                          • Word of the Day

                                            Zoho Marketing Automation

                                              Zoho Sheet Resources


                                                  Zoho Forms Resources

                                                    Secure your business
                                                    communication with Zoho Mail

                                                    Mail on the move with
                                                    Zoho Mail mobile application

                                                      Stay on top of your schedule
                                                      at all times

                                                      Carry your calendar with you
                                                      Anytime, anywhere

                                                            Zoho Sign Resources

                                                              Sign, Paperless!

                                                              Sign and send business documents on the go!

                                                              Get Started Now

                                                                      Zoho TeamInbox Resources

                                                                              Zoho DataPrep Resources

                                                                                Zoho DataPrep Demo

                                                                                Get a personalized demo or POC

                                                                                REGISTER NOW

                                                                                  Design. Discuss. Deliver.

                                                                                  Create visually engaging stories with Zoho Show.

                                                                                  Get Started Now

                                                                                                      • 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

                                                                                                        Some configuration options mentioned in this page like validation preference, error location, and validation on are being released in a phased manner. They may not be available in your account. They will soon be released to all customers in all DCs. ...
                                                                                                      • FAQs: Validation Rules

                                                                                                        What is a validation rule in Zoho CRM and why do I need it? In this data-driven world, it is crucial to ensure the validity and accuracy of your data. Data can enter your CRM system through various channels, such as advertisements, web forms, ...
                                                                                                      • Points to note while updating a field used in a validation rule.

                                                                                                        Validation Rules are effective on creating a record manually. However, when fields used in a validation rule (whether primary or secondary) are updated through other ways such as workflow update, and APIs, the field update takes precendence over the ...
                                                                                                      • FAQs: Case Escalation Rules

                                                                                                        What is a Case Escalation Rule and why do I need it? A case is a trouble ticket that is submitted by your customer to capture their feedback on various types of issues that arise after purchasing a product or service from your company. Sometimes ...
                                                                                                        Wherever you are is as good as
                                                                                                        your workplace



                                                                                                          Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.


                                                                                                          Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.


                                                                                                          Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.

                                                                                                          CRM Tips

                                                                                                          Make the most of Zoho CRM with these useful tips.

                                                                                                            Zoho Show Resources