Qntrl | Online Help | Business case 2: Fetch data from third party websites using Server Scripts (Before Create)

Business case 2: Fetch data from third party websites using Server Scripts (Before Create)

We might sometimes want to fetch external data from other applications or websites like weather details, stock rates, or flight status related to the card, when we create a card. Server scripts can be used to fetch such data and display it in Qntrl.
 

Business Scenario

Zylker Corp associates with a set of vendors whose details are saved in a cloud database. When a new card is created for a vendor, all the vendor details are mentioned in the card repeatedly. If the details get populated automatically, it will save quite a substantial amount of time and reduce manual errors.
 

Solution

As soon as the ‘Vendor ID’ field is filled in the card, the other details like ‘Vendor Name’, ‘Address’, and ’Contact’ should be automatically populated in the card fields. To execute this:
  1. Create a form with different custom fields to hold the vendor details.
  2. Create a server script to fetch data from the third-party application.
  3. Create a card and fill the index field to populate other fields automatically.
 

Sample Configuration

Step 1: Create an orchestration

Create a new orchestration titled 'Contract Initiation' and add the following custom fields to it:
  1. Vendor ID
  2. Vendor Name
  3. Website
  4. Vendor Email
   

 
Once the form is saved, proceed to design the blueprint, set permissions, and publish the orchestration.
 

Step 2: Code server scripts

Code the server script to fetch and populate vendor details.
  1. Create a new server script and enter the name as 'Fetch vendor details'.
  2. Choose Contract Initiation in the Form dropdown.
  3. Choose Job as the Execution Location to execute the script.
  4. Choose Before Create  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. 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 beforeCreate(){
  2.     var job = current.Job;      
  3.     var fields = current.Layout.Fields;
  4. //Select Vendor ID parameter here
  5.     var vendorId = current.Job.getValue(current.Layout.Fields.<select-VendorID-parameter-here>.id);
  6.     if (!vendorId) {
  7.         console.log("Invalid vendor ID");
  8.         return;
  9.     }
  10.  
  11.     var url = "https://jsonplaceholder.typicode.com/users/"+vendorId;
  12.     var params = {};
  13.     var headers = {};
  14.  
  15.     var res = ZDK.HTTP.get(url, params, headers);
  16.     if (res.status != 200) {
  17.         console.log("Unable to fetch vendor details");
  18.         return;
  19.     }
  20.     var responseBody = res.body;
  21.     if (typeof responseBody == "string") {
  22.         responseBody = JSON.parse(responseBody);
  23.     }
  24.  
  25.    //Select parameters here
  26.  job.setValue(fields.<select-VendorName-parameter-here>.id, responseBody.name);
  27.     job.setValue(fields.<select-VendorEmail-parameter-here>.id, responseBody.email);
  28.     job.setValue(fields.<select-Contact-parameter-here>.id, responseBody.phone);
  29.     job.setValue(fields.<select-Website-parameter-here>.id, responseBody.website);
  30.     
  31.     console.log("Vendor details filled for the vendor " + vendorId);
  32. }



Step 3: Add card

When the orchestration and server script 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.
    1. Other vendor details must be auto-populated.
  4. Save the card.
     

 

    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
                          CRM 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 Estate Kiosk in Mobile Forms
                          Electronic Forms

                          Notification Emails for Forms Alternatives Security & Compliance
                          Holiday Forms Google Forms alternative  GDPR
                          Form to PDF Jotform alternative HIPAA Forms
                          Email Forms
                          Encrypted Forms
                          Embeddable Forms
                          Secure Forms
                          Drag and Drop form builder
                          WCAG


                                            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