Kaizen 250: Introducing write-enabled Queries: Auto-populating lookup fields

Kaizen 250: Introducing write-enabled Queries: Auto-populating lookup fields


Hello Everyone,

Welcome back to an exceptional edition of the Kaizen series!
Today marks Kaizen #250, an exciting milestone in our journey of exploring, learning, and building with Zoho CRM. Over the past 249 editions, we've covered a wide range of features, APIs, best practices, and real-world use cases designed to help you get more out of Zoho CRM. A heartfelt thanks to everyone who has followed the series, shared feedback, asked thoughtful questions, and supported this journey along the way.

In today's post, let's explore the latest enhancements to Queries.


Until now, we've primarily used Queries as a read-only capability allowing us to fetch data, transform it using a Serializer, and display it in components such as Canvas and Kiosk. However, whenever we had to update a CRM record, such as setting a lookup field or modifying a value we had to rely on Custom Functions or Client Scripts. 

Info

What's new

Query Workbench's REST API source type supports GET, POST, PUT, PATCH, and DELETE, which means a Query can now perform the write itself, end-to-end.

Why this matters

The latest enhancement to the Queries feature enables you to automate dynamic lookup assignments directly within Zoho CRM. In this post, we'll use a practical example to show how this enhancement works in a Blueprint-driven Kiosk flow.
Quote

Business scenario

Zylker Field Services manages a team of Field Engineers across multiple service zones. Whenever a new Service Application is created, a dispatcher is responsible for manually identifying the most suitable engineer by matching the application's Zone and Specialization, and selecting the engineer with the lowest Active_Request_Count before assigning the request.

The Operational Problem

Traditionally, this process is manual:
  1. The dispatcher opens the Field Engineers module.
  2. Filters engineers by the required Zone and Specialization.
  3. Compares each engineer's Active_Request_Count.
  4. Assigns the engineer with the lightest workload.
This approach is both time-consuming and difficult to scale. As the number of service requests and engineers grows, manually comparing workloads becomes inefficient and can lead to uneven distribution of work.
Idea

Solution Overview

To automate engineer assignment, we'll build a Kiosk that is triggered from the Assign Engineer Blueprint transition. The Kiosk uses GetRecords state to retrieve the most suitable engineer and update the required records directly through the Queries with Zoho CRM REST API source.

The solution works as follows:
  1. The Kiosk is launched when the Service Application enters the Assign Engineer Blueprint transition.
  2. The GetRecords state fetches the Field Engineers module for engineers who match the Service Application's Zone and Specialization, filters only active engineers, and sorts the results by Active_Request_Count in ascending order.
  3. If a matching engineer is found, the Kiosk, updates the Field_Engineer lookup field on the Service Application by invoking the Query.
  1. Finally, the Kiosk displays a confirmation message and completes the Blueprint transition.

  2. If no suitable engineer is found, the Kiosk notifies the dispatcher, preventing the transition from completing until the assignment can be handled manually.

This approach ensures that every Service Application is assigned to the best-fit, least-loaded engineer while keeping the implementation entirely within native CRM components. 

Implementation

Step 1: Create a Query to Update the Field Engineer Lookup in Service Application Module

  1. Navigate to Setup -> Developer Hub -> Queries.
  2. Click Create Query, provide a name, and click Next. 
  3. In the Query Workbench, select Zoho CRM REST API as the Source. 
  4. Set the Request Method to PUT. 
  5. Specify the relative path for the Update Records API, passing the Service Application record ID as a variable. 
    /v8/Service_Applications/{{service_record_id}}

  6. Select Raw as the Body Type.
  7. Enter the following request body. The Kiosk dynamically populates the lookup field values. 
    {
     "data": [
     {
     "id": "{{service_record_id}}",
     "Field_Engineer": {
     "id": "{{engineer_id}}",
     "name":"{{engineer_name}}"
     }
     }
     ]
    }

  8. Provide the code to the Serializer to format the response according to your requirements. If the result contains data it will return "Field Engineer Assigned".
    const apiResult = result?.data?.[0] ?? {};

    return [{
     Message: "Field Engineer Assigned" ?? "Engineer Lookup Field Update Failed"
    }];

  9. Click Execute Query to verify the request and Save the Query.
      

Step 2: Create a Kiosk to Retrieve and Assign the Field Engineer

Create a Kiosk that retrieves the most suitable engineer and updates the Field_Engineer lookup field during the Blueprint transition.
  1. Navigate to Setup -> Customization -> Kiosk Studio
  2. Click Create Kiosk
  3. Provide a name and click Next
  4. Select Service Applications as the current module.


Add a Get Records state

  1.  Add a Get Records state and name it Get Suitable Field Engineer. 
  2.  Associate the Query that retrieves Field Engineers based on:
    1.  Zone 
    2.  Specialization 
    3.  Active status 
  3. Sort the results by Active_Request_Count in ascending order so that the least-loaded engineer is returned.  

Add a Decision state

  1.  Add a Decision state after the Get Records state. 
  2.  Name the decision Engineer Found. 
  3.  Configure the condition to check whether the Query returned a matching engineer. 
  4.  Create two paths: 
    1. Assign Engineer
    2. Default


Configure the Assign Engineer path

  1.  Add a Screen to the Assign Engineer path. 
  2.  Click Add and select Get data via Queries. 
  3.  Click New Query and associate the Query created in Step 1. 
  4. Map the required variables from the Get Records response and the current record. 
  5.  Select the fields to display on the screen. 
  6.  Click Save, and then Done

Configure the Default path

  1.  Add another Screen to the Default path. 
  2. Display an appropriate message, for example: "No matching service engineer is currently available. Please assign an engineer manually to continue".
  3.  Click Publish to save the Kiosk.

Step 3: Associate the Kiosk with the Blueprint Transition

Associate the Kiosk with the Assign Engineer Blueprint transition so that it is launched automatically whenever the transition is executed.
  1. Navigate to Setup > Process Management > Blueprint.
  2. Open the Blueprint created for the Service Applications module.
  3. Select the Assign Engineer transition.
  4.  Click Add(+) in the During tab.
  5. Choose Kiosk from the list of associated items.
  6. Select the Map Service Engineer Kiosk that you created in the previous step.
  7. Save the Blueprint.



The Outcome

When a user creates a Service Application, the record is initially created in the Open state. The Assign Engineer Blueprint transition is then available for execution. When the user clicks the Assign Engineer transition, the associated Kiosk launches automatically. The Kiosk retrieves the most suitable Field Engineer based on the application's Zone and Specialization, updates the Field_Engineer lookup field on the Service Application, and completes the assignment. If no matching engineer is found, the Kiosk displays an appropriate message, preventing the transition from proceeding until the assignment is handled manually.

We hope you found this post useful. 
We would love to hear from you! Write to us at support@zohocrm.com.

Happy Querying!