Hello everyone!
Welcome back to another week of Kaizen!
We released the Queries feature sometime back and hope you have tried it out.
A little gist about this feature before we move on to our post.
Zoho CRM's Queries feature enables dynamic data retrieval from both CRM modules and external services, facilitating seamless integration and informed decision-making.
Key Components
- Sources: Pre-configured sources like Modules and COQL are available, with the option to add custom sources via REST APIs.
- Queries: Fetch data by selecting modules, writing COQL statements, or specifying REST API endpoints, headers, and parameters.
- Variables: Incorporate variables in criteria, COQL statements, and endpoints to pass dynamic values during execution.
- Schema: Auto-generated schemas define the structure of query responses, with editable paths, field types, and labels for customization.
- Serializer: Utilize JavaScript to manipulate and customize query responses, ensuring data is in the desired format for further processing.
Types of Queries
- Modules: Retrieve records by selecting specific modules and fields, applying conditions to filter data as needed.
- COQL (CRM Object Query Language): Write SQL-like queries to fetch data, supporting complex operations like joins and aggregations.
- REST API: Fetch data from external services by specifying endpoints, headers, parameters, and connections.
With the Queries feature, you can efficiently access and display relevant data within Zoho CRM, enhancing workflow efficiency and decision-making capabilities.
A little insight into Functions before we dive into today's Kaizen!
Functions, Queries, you get the connection, right? Read on!
Many of us use Functions in Zoho CRM extensively to perform our business logic and customize the way things work in Zoho CRM. You can use Functions in blueprints, workflows, Circuits etc.
Let's say you have a function that gets the employee records from the Employees module. Technically, the function executes an API call or an integration task, and gives a response.
The response can be a string or map(JSON), depending on how the function is written and where it is used. Since functions can be used in many places, the same response format may not be the right one to be used in a circuit or a workflow.
This is where the genie 'crmAPIResponse' object comes into picture!
The power of the 'crmAPIResponse' object
The crmAPIResponse object to be returned in the CRM function should encapsulate the response in a way that it can be used in Queries, Circuit, workflow etc. The details needed are encapsulated as a map. It should include details like crmStatusCode, status, message, body in order to construct the desired format for handling data and customizing the error handling logic.
Let's consider the following example function where we use the getRecordByID integration task.
The response of the integration task contains all the fields in that module, but we want only certain parts of the response JSON and also add custom error messages, to be used in other components like Queries, Circuits, etc,.
Here is the code.
{ leadId = "3652397000018025772"; // Replace with a valid Lead ID
// Initialize customAPIResponse map customAPIResponse = map();
// Fetch lead details crmResponse = zoho.crm.getRecordById("Leads", leadId);
// Log the raw response for debugging info "CRM API Raw Response: " + crmResponse;
// Validate and process the response to include only the required fields if (crmResponse != null && crmResponse.containsKey("id")) { // Extract required fields filteredData = map(); filteredData.put("id", crmResponse.get("id")); filteredData.put("Last_Name", crmResponse.get("Last_Name")); filteredData.put("Email", crmResponse.get("Email"));
customAPIResponse.put("crmStatusCode", 200); customAPIResponse.put("status", "success"); customAPIResponse.put("message", "Lead data retrieved successfully."); customAPIResponse.put("body", filteredData); // Include only filtered data } else { customAPIResponse.put("crmStatusCode", null); customAPIResponse.put("status", "error"); customAPIResponse.put("message", "Invalid or null response from Zoho CRM API."); customAPIResponse.put("body", null); }
// Return the customAPIResponse return {"crmAPIResponse": customAPIResponse};
} |
Here, you can see that we have parsed the response of the integration task to get the Last_Name, Email, and record ID using the crmResponse.get("field_API_name") statement and constructed the customAPIresponse object using the customAPIResponse.put("key", "value") statement.
The statement return {"crmAPIResponse": customAPIResponse}; returns the response body as depicted in the previous statements.
Response to the info "CRM API Raw Response: " + crmResponse; statement
"CRM API Raw Response: {"Owner":{"name":"Patricia Boyle","id":"3652397000000186017","email":"p.boyle@zylker.com"},"$field_states":null,..}}} |
Response of the return {"crmAPIResponse": customAPIResponse}; statement
{ "crmAPIResponse": { "crmStatusCode": 200, "status": "success", "message": "Lead data retrieved successfully.", "body": { "id": "3652397000018025772", "Last_Name": "Math", } } } |
Error response
{ "crmAPIResponse": { "crmStatusCode": null, "status": "error", "message": "Invalid or null response from Zoho CRM API.", "body": null } } |
You can see that we have used the crmAPIResponse object to get only the required keys from the response and constructed a much simpler response.
Finally, to today's Kaizen!
We've established that you can use the crmAPIResponse object to construct responses in a way that's suitable to be consumed at another place like a circuit or a workflow.
We also know that Queries allows you to have sources of the REST API type to fetch data from various sources. This means that you can have a standalone function that is enabled as a REST API as a source in Queries.
Let's see an example.
There is a simple function that uses the getRecords integration task to get the records from the Employees module.
I have used the crmAPIresponse object to construct a response as shown in the following code.
string standalone.getRecords() { result = zoho.crm.getRecords("Employees"); response = Map(); response.put("status_code",200); response.put("body",{"code":"success","details":result,"message":"function executed successfully"}); return {"crmAPIResponse":response}; } |
The response of this function is a string in the crmAPIResponse object as shown in this image.
- Save this function and enable REST API.
- You can see that the domain is https://www.zohoapis.com. To be able to use this in a Query, register this domain in Trusted Domain.
- To create a REST API type source, you must add the source. Go to Setup > Developer Hub > Queries > Sources tab.
- Click Add Source and give the details like the name, base URL, headers, and parameters under the Information section.
- Click Save.
- Go to the Queries tab and click Add Query.
- For Source, choose the source you just added.
- Under Information, enter the name, API name of the query.
- For the endpoint, enter the API Key URL of the function.
- Enter the parameter name and values in the Parameter field.
Click Add Serializer if you want to serialize the response. In this example, I have serialized the response to include only the Name, Email, and Position fields in the output. The result contains the 'body' object that we returned in the crmAPIResponse object of the function.
- Click Save to save the serialization.
- Click Next to view the schema of the query. Make changes as required.
- Save the query.
You can now use this query in Canvas or associate it with Kiosk to solve your business needs.
Let us see how the crmAPIResponse object in the function affects the response of the query.
Query with the function without crmAPIResponse:
Let's consider that the function getRecords() does not use the crmAPIResponse object. In that case, the function returns a response that is a string. This response string cannot be serialized or used elsewhere.
Schema of the query without crmAPIResponse:
Query with the function with crmAPIResponse and serialization:
The same getRecords() function that uses the crmAPIResponse object allows you to construct the response as JSON. You can serialize this response easily and use it in a circuit, query, workflow etc.
You can see here that the response is now a JSON.
Schema of the query with crmAPIResponse:
In conclusion, you can use the crmAPIResponse object in Functions to construct the desired response and use the REST API-enabled function as a source in Queries.
Leveraging the advantage of the crmAPIResponse object in functions and using it in Queries increases the prospect of solving many more business cases easily and customize more efficiently.
We hope you liked this post and found it useful. Let us know your thoughts in the comments.
If you'd like us to cover any other topic in this series, feel free to comment or reach us at support@zohocrm.com.
Cheers!
------------------------------------------------------------------------------------------------------------------------------------------------
See Also
Recent Topics
Zoho Payroll's Year in Review 2024
As we roll into 2025, we'd like to pay tribute to all the milestones we hit in 2024! From releasing out new features that streamlined your workflows to updates that made payroll management smoother, we’ve had a prolific year—all while keeping you, our
Key Highlights of 2024: Recalling a Year of Progress and Advancements!
As we step into 2025, we’re excited to share the progress and developments we’ve made to simplify and streamline your travel and expense management in the past year. Let’s take a look back at some of the key updates and enhancements that have helped us
Ticket Views: filter criteria -> dynamic date values in relation to the current date
Hello all, It would be very helpful if you could build custom views in such a way that you do not have to adjust the criteria daily or at whatever interval in order to change the fixed date value as needed. For example, I would like to create a view that,
How can I understand in the search results which collection a note is in and how to immediately go to this collection?
How can I understand in the search results which collection a note is in and how to immediately go to this collection? You can call the note properties window, but only the notepad is listed there. This is very inconvenient, especially when there are
Zoho Desk Validation Rule Using Custom Function
Hi all, I tried to find the way to validate fields using custom function just like in Zoho CRM but to no avail. Is there a way to do this?
Is there a way to request a password?
We add customers info into the vaults and I wanted to see if we could do some sort of "file request" like how dropbox offers with files. It would be awesome if a customer could go to a link and input a "title, username, password, url" all securely and it then shows up in our team vault or something. Not sure if that is safe, but it's the best I can think of to be semi scalable and obviously better than sending emails. I am open to another idea, just thought this would be a great feature. Thanks,
How to easy change layout in existing records in Deals?
Hello, So far i have used only 1 layout in Deals. I have about 1000 records. Now i want to make new layout. So i have 2 layouts: Layout Old (1000 records) Layout New (0 records) How to easy change layout from Layout Old into Layout New for existing records?
Link Images to a Excel Report
When I export to a spreadsheet. How do I get it to create a link that goes to my image. Right now it shows up in Excel as: /sharedBy/appLinkName/viewLinkName/fieldName/image/1510098844838_Image_07-Nov-2017_18_54_03.jpg
Possible to change Deal Stage via Deluge function in a Workflow automation when there's a Blueprint implemented for the pipeline?
I've configured a Blueprint for my Deals module pipeline. I want to change the Stage value for a Deals module record through a Deluge function in a Workflow Rule, but I get this error message: "Deals record update response = {"code":"RECORD_IN_BLUEPRINT","details":{"api_name":"Stage"},"message":"Stage
Alert for Back Navigation in Zoho Creator Widgets on Mobile Apps
In Zoho Creator widgets, when a user navigates back on mobile devices, the data within the widget is reset. This leads to a loss of any unsaved changes or inputs, causing frustration for users. To enhance user experience, we need to implement a confirmation
Limit excceding issue in zoho creator
I am transferring data from Zoho Books to Zoho Creator using a Deluge script. However, I am frequently encountering a "limit exceeding error," which seems to be related to the Deluge statements limit. I reached out to Zoho Support, and they informed me
Explication sur comment mettre en place des règles d'affichage ou "layout Rules"
J'ai passé plus d'une heure hier avec le support et je n'ai rien compris !! Je suis lecteur assidu des guides (je "RTFM") qui ne sont absolument pas orienté "client" chez Zoho, et je tiens à le rappeler ici . Dans la documentation on m'indique un cas
Create custom rollup summary fields in Zoho CRM
Hello everyone, In Zoho CRM, rollup summary fields have been essential tools for summarizing data across related records and enabling users to gain quick insights without having to jump across modules. Previously, only predefined summary functions were
Matching ZOHO Payments in Banking
Our company has recently integrated ZOHO Payments into our system. This seemed really convenient at first because our customers could pay their account balance by clicking on a link imbedded in the emailed invoice. Unfortunately, we can't figure out how
Projectic Specific Calendar Dates
We are trying to create a project request form. One of the first fields is a multiple choice field that requests the user to select the type of project they are requesting. We are wanting to have a calendar view that changes the allowable dates to be
Off cycle pay run 10 day
How would I go about running an off cycle pay run for 10 days? (Jan 1-10)? I have been trying to be in contact with support and we keep paying phone tag. I need to change my pay period from bi-weekly to weekly. This should be much easier than they are
Set another Layout as Standard
We created a few layouts and we want to set another one to standard:
Values in multi pick list are not copied to copied deal
Hi, After a deal is completed in our sales funnel we copy the deal to an automatically created new deal in our project funnel. All fields are copied properly, but only a Multi Pick List is not copied. How can we copy the selected values in this field
Change Last Name to not required in Leads
I would like to upload 500 target companies as leads but I don't yet have contact people for them. Can you enable the option for me to turn this requirement off to need a Second Name? Moderation update (10-Jun-23): As we explore potential solutions for
Creation of Path and subpath
In order to improve the structure of the website for better organization, I would like to consider that when publishing a page, it can be within a section and sub-section. For example, if I have an events option in the menu, I can put past events and
Kaizen #172 - Leveraging the 'crmAPIResponse' Object in Queries
Hello everyone! Welcome back to another week of Kaizen! We released the Queries feature sometime back and hope you have tried it out. A little gist about this feature before we move on to our post. Zoho CRM's Queries feature enables dynamic data retrieval
"We’ve fine-tuned Zoho Inventory..."
Every day I have this message at the top of my screen. I hit refresh everyday and then the next I see it again. What is being "fine-tuned" on a daily basis?
Default Sort Order in Project Tasks View
It should be possible to specify a default sort order (or have the last explicit sort order restored upon reload) for the tasks in the project tasks view. Currently the sort order must be manually re-selected for each sub-group whenever any changes are
BIN Locations
Hi, I’m new to Zoho inventory and unless Im missing something, I cannot find BIN locations anywhere in ‘items’? please tell me it’s there somewhere?!? Thanks
How to query for Deals record based on Pipeline?
I want to query for Deals records that matches a specified Pipeline using a Deluge function. When I call zoho.crm.searchRecords("Deals","(Pipeline:equals:" + myPipeline + ")"), I get this error: { code: 'INVALID_QUERY' , details: {...} , message: 'Invalid
Status properties
Hello, I created a new status called "Hold", but I want Zoho to recognize that when a project is on "Hold" the tasks will not appear as open and the deadlines will not show as delinquent. Basically, freezing the project until it's ready to start up again.
Need to change author's name in blog post
My colleague wrote a blog post for our blog but when I put it on our site, the author's name automatically populated as mine. I contacted ZohoSupport and was told to change the Nickname in my profile. Well, I did and then ALL the blog posts were listed as being written by my colleague! Is there any way to simply change one blog post with the correct author's name?
Getting 401 Unauthorized while creating Ticket
I'm getting 401 UnAuthorized when I try to create a ticket using the Zoho Desk API. I am using using OAuth2.0 for getting access token and generated accesstoken and used Desk.tickets.ALL as a SCOPE . Kindly help me to resolve this issue while creating
Rich-text fields in Zoho CRM
Hello everyone, We're thrilled to announce an important enhancement that will significantly enhance the readability and formatting capabilities of your information: rich text options for multi-line fields. With this update, you can now enjoy a more versatile
What do the Image Sizes mean in Zoho CRM Email Templates?
Below you can see the image options in email templates: Banner, Fit, Small, Medium, Original, Custom. Can someone from Zoho please share with me: What each is/means? How each will look on desktop AND mobile? How to edit "custom"? If I choose "Custom"
Marketing Automation : Adding to existing Lead Score
I want to be able to add a score to an existing ZMA lead however I can't find the field in the "Fetch Lead" action that contains the existing score. There is an action for Add lead score, but that's not clear if it overwrites the existing value or adds
Zoho developer edition does not work for us
Hi Is anyone else having this problem? I'm signed in with our admin/super user account. When I click on the link on this page: https://www.zoho.com/crm/developer/docs/dev-edition.html I am asked to agree to Terms and Conditions. Clicking Agree to Terms
Option to specify or disable "Idle" times in preferences
It seems strange to me that my Cliq shows me as "Idle" when I'm using the PC and available just because I haven't interacted with Cliq in a while. I'm far from "Idle" so we're just treating "Idle" and "Available" to mean the same thing. I'd like to suggest a setting to change the timeout or even disable the automatic "Idle" mode.
Changing Color Theme of Guided Conversations
Hello, We have recently added Guided Conversations to one of our websites, but I am wondering if there is a way to customize the color scheme so it matches the appearance of the website? Thank you in advance!
Is there a Kanban view of Tasks across all Projects?
As the title indicates, I could use a Kanban view of my Tasks across my Projects. If it's there, I don't see it. If it isn't there, I'd like to submit this as a feature request. Thx.
Create Invoice and Invoice Items from Sales Order via API
Currently, when creating an Invoice associated with a Sales Order via the API, it appears that I must manually include all of the items (line_items) even though they are already part of the Sales Order. My question is this: is it possible to raise an Invoice via the API based on all of the information associated with a Sales Order--such as the items? In other words, do I always have to manually include the items (line_items) when raising an Invoice via the API when the Invoice is associated with
Stock Count - Does it really work?
We have been trying to use the new Zoho Inventory stock count feature. It seems great at first glance.. ..but what we can't get our heads around is if a count doesn't match you can't simply set up a recount of those that are unmatched, which just seems
Working with keywords
Hello everyone, first time here so I will try to be brief. I am working on my company's data set. I have a table with all the images we have on line. For each image we hava a cell tha contains all keywords related to that image. I would like to explore
Microsoft Phone Link
Does anyone know if you can use Microsoft Phone Link to make calls through Zoho?
Free user licenses across all Portal user types
Greetings everyone, We're here with some exciting and extensive changes to the availability of free user licenses in CRM Portals. This update provides users with access to all Portal user types for free to help them diversify their user licenses and explore
Next Page