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.


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.     }
  11.     var url = "https://jsonplaceholder.typicode.com/users/"+vendorId;
  12.     var params = {};
  13.     var headers = {};
  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.     }
  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);
  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.


    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 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

                  Zoho SalesIQ Resources

                      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



                                                          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