Qntrl | Online Help | Business case 3: Validate new data entered in cards using Server Scripts (Before Update)

Business case 3: Validate new data entered in cards using Server Scripts (Before Update)

Performing operations and coordinating with teams can be quite a herculean task. If the information given in the card details is changed to corrupt information later, it may create chaos and slow down task completion. This is why if a user is to make updates in the card, server scripts allow to validate the new data before it is updated in the card.
 

Business Scenario

Zylker Corp associates with a set of vendors whose details are saved in a cloud database. When vendor details in an existing card are updated, the details have to be validated with the existing values in the database. If the updated detail is wrong, the card must not be allowed to be saved.
 

Solution

When a vendor detail field is updated in the card, the new value can be validated with the database using server scripts. To execute this:
  1. Create a server script to validate data from the third-party application.
  2. Create a card and update a field to test the functionality.

Sample Configuration 

Step 1: Code server scripts

Create a new server script to validate vendor details if they are updated.
  1. Create a new server script and enter the name as 'Validate vendor details'.
  2. Choose Contract Initiation  in the Form dropdown. We've used the previous use case's orchestration here. Learn more.
  3. Choose Job as the Execution Location to execute the script.
  4. Choose Before Update  as the Execution Trigger to execute this script whenever the card page loads.
  5. Copy and paste the below script into your script editor and replace the parameter names.
    1. This code is to validate the vendor name alone. You can use similar logic to validate other details.
    2. You can use the ? Icon at the top-right corner of the script editor to refer to parameter names.
  6. Once the script is ready, Publish it. 

  1. function beforeUpdate(){
  2.  
  3.     //select Vendor ID parameter here
  4. var vendorId = current.Job.getValue(current.Layout.Fields.<select-VendorID-parameter-here>.id);
  5.     if (!vendorId) {
  6.         console.log("Vendor ID not present");
  7.         return;
  8.     }
  9.     var url = "https://jsonplaceholder.typicode.com/users/"+vendorId;
  10.     var params = {};
  11.     var headers = {};
  12.  
  13.     var res = ZDK.HTTP.get(url, params, headers);
  14.     if (res.status != 200) {
  15.         console.log("Unable to fetch vendor details");
  16.         return;
  17.     }
  18.     var responseBody = res.body;
  19.     if (typeof responseBody == "string") {
  20.         responseBody = JSON.parse(responseBody);
  21.     }
  22.  
  23. //select Vendor Name parameter here
  24.     var orginalVendorName = responseBody.name;
  25.     var presentVendorName = current.Job.getValue(current.Layout.Fields.<select-VendorName-parameter-here>.id);
  26.     if (orginalVendorName != presentVendorName) {
  27.         current.Job.addError(current.Layout.Fields.<select-VendorName-parameter-here>.id, "Vendor name is not matching in vendor database");
  28.     }
  29. }



Step 2: Add card

When the orchestration and server scripts are ready, we can test the script by creating a new card .
  1. Navigate to Cards and click Add Card.
  2. Select Contract Initiation  from the Form dropdown.
  3. Enter the vendor ID to auto-populate other vendor details and Save the card.
  4. In the card details page, update any vendor detail, such as Vendor name, Address, Website, Contact, or Vendor email.
  5. If the detail entered does not match with the details in the database, an error will be displayed and the card will not be allowed to be saved.


 

    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









                                            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









                                                                                                                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