Validation Rule Using Functions | Online Help - 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. Select the module for which you want to create the validation rule.
  3. In the [Module] page, click the Validation Rules tab.
  4. Click Create New Validation Rule.
  5. In the Create Validation Rule pop-up, perform the following actions:
    1. Select the layout that the field you wish to validate belongs to.
    2. Select the field to validate.
    3. Select the validation type as Using function.
    4. Select either Save Only or Field Verify and Save from the Validate on dropdown.

    5. Click Next.
  6. On the Configure Function page, do either of the following:
    1. Click Functions > Choose a function > Configure > Save.
    2. Click Write your own > Enter the function > Save.
  7. Click Save to save the validation rule.


Note
The functions that are created in the Functions Tab can be associated with validation rule. 
  1. Go to Setup > Developer HubFunctions > + New Function.
  2. In the Create New Function popup, select Validation Rule from the Category drop-down list.

    Access your files securely from anywhere

      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






                          Quick Links Workflow Automation Data Collection
                          Web Forms Enterprise Begin Data Collection
                          Interactive Forms Workplace Data Collection App
                          Encrypted Forms Customer Service Accessible Forms
                          Digital Forms Marketing Forms for Small Business
                          HTML Forms Education Forms for Enterprise
                          Contact Forms E-commerce Forms for any business
                          Lead Generation Forms Healthcare Forms for Startups
                          Wordpress Forms Customer onboarding Order Forms for Small Business
                          No Code Forms Construction RSVP tool for holidays
                          Free Forms Travel
                          Prefill Forms Non-Profit

                          Intake Forms Legal
                          Mobile App
                          Form Designer HR
                          Mobile Forms
                          Card Forms Food Offline Forms
                          Assign Forms Photography
                          Mobile Forms Features
                          Translate Forms Real EstateKiosk in Mobile Forms
                          Electronic Forms

                          Notification Emails for Forms Alternatives
                          Holiday Forms Google Forms alternative 
                          Form to PDF Jotform alternative





                                            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

                                                                                                              • 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, ...
                                                                                                              • 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 ...
                                                                                                              • 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: 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, ...
                                                                                                              • 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 ...
                                                                                                                Wherever you are is as good as
                                                                                                                your workplace

                                                                                                                  Resources

                                                                                                                  Videos

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



                                                                                                                  eBooks

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



                                                                                                                  Webinars

                                                                                                                  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