Manipulating Subforms from third-party Application using Functions

Manipulating Subforms from third-party Application using Functions

Hey folks! Welcome to a fresh week of Kaizen. 

In this post, we will see how to work with subforms and external fields in a module through CRM functions. 

Consider a scenario where a High School utilizes Zoho CRM to manage student records, academic performance, and offered courses. Additionally, the school employs an Exam portal for students to take examinations. After the examination, the portal sends the mark information back to Zoho CRM along with it's own course id, student id, marks & other details. 

Problem Statement 

When the exam portal initiates a webhook call to CRM, the high school management wants to capture that data and update the CRM subform records accordingly. This subform should act as a semester progress report for each student.  

Solution Overview 

To address this requirement, a custom function must be implemented. The webhook URL will be the API REST URL of the custom function in Zoho CRM. Upon receiving the notification, the function is triggered, and the details from the notification are used to manipulate the subform.

Let us walk through this process of triggering functions using a webhook to manipulate subforms. 

Prerequisites 

From the Third-Party Application 

  • We assume that a webhook will be triggered from the third-party application when the exam is over and evaluated by the teacher. The webhook will carry the following information:  
Field
Data Type
Description
Exam Name
String
Name of the examination that the student attends.
Student ID
Long String
Unique ID of the student within the Portal App.
Course ID
Long String
Unique ID of the course within the Portal App.
Marks
Integer
Total marks of the student in the particular course.
Total Time
Integer
Time taken by the student to complete the exam.

  • The webhook URL should correspond to the API REST URL of the custom function in Zoho CRM.  

From Zoho CRM 

Here is a data model image of the CRM modules involved in this scenario for your ease of understanding.  



The Courses, Students and Student Exams modules are assumed to be pre-loaded with records. Following are the module wise fields that are expected to be already configured in the school's CRM org.  

Courses and Students Modules 

External fields named Student Code in the Students module and Course Code in the Courses module are used to match the IDs deployed in the third-party application. 



Note
      External fields can be updated only using the Update Records API.

Student Exams Module 

Following are the custom fields that we assume to be already available in the Student Exams module. 

Field Name
Data Type
Description
Student
Lookup
The field looks up to the Students module.
Total Marks
Integer (Formula)
A subform aggregate field that sums up the values of the Marks field in the Student Performance subform.
GPA
Integer (Formula)
Calculates the GPA of a student in that particular examination.
Exam Name
String (Picklist)
List downs the examinations that are planned to be conducted for the academic year.
 


Student Performance Subform 

A subform named Student Performance within the Student Exams module, comprising the following fields.

Field Name
Data Type
Description
Course
Lookup
Represents the course name and it looks up to one of the courses from the Courses module.
Total Time
Integer
Time taken by the student to complete the exam.
Marks
Integer
Marks of the student in the particular course.

Grade
String (Formula)
Grading system is infused as formula and it works depending on the value in the Marks field.



The subform is assumed to be empty and will be updated only on receiving a webhook notification from the Portal App. 

Note 
      Make a Modules Metadata API call to get the API names of the modules and the subform. Next, fire the GET Fields API call to get the API names of the fields. We will need them in crafting the custom function. 

Creating the Custom Function 

Step 1: Navigate to the Setup > Developer Hub > Functions and click the New Function button. 



Now, create a Standalone function by filling in the details. 


Flow of the Function 

Argument Setup 

Define function arguments to receive details from the function as shown here: 



Data Retrieval 

Invoke the COQL API within the function to retrieve the necessary records from the Student Exams and Courses module. 

student_examMap = Map();
student_examMap.put("select_query","select id from Student_Exams where Student.Student_Code =" + student_id + " and Exam_Name=" + exam_name + " limit 1");
exam_response = invokeurl
[
type :POST
parameters:student_examMap.toString()
connection:"crm_oauth_connection"
];
exam_id = exam_response.getJSON("data").get(0).get("id");

Here, the query is structured to retrieve the ID of the Student Exam record where the Student lookup field corresponds to the record with the Student Code matching the student_id in the notification, and the Exam Name picklist field matches the value of exam_name from the notification. 

Note: You can use only =, !=, in and not in operators for querying External fields in Zoho CRM. 

courseMap = Map();
courseMap.put("select_query","select id from Courses where Course_Code =" + course_id + " limit 1");
course_response = invokeurl
[
type :POST
parameters:courseMap.toString()
connection:"crm_oauth_connection"
];
course_id = course_response.getJSON("data").get(0).get("id");

In this COQL call, the query fetches the ID of the record from the Courses module whose Course Code field matches the course_id received in the notification. 

Subform Update Handling

The custom function should address the following three cases inorder to effectively manipulate the subform data from the third-party application. 
  • Every webhook call from the Exam portal should be added as a new entry to the subform.
  •  If entries already exist in the subform, the function should perform PATCH operation.
  • Before executing the PATCH operation, it is crucial to check whether the webhook call is for a new course or an update to the existing course. In such cases, the function should refrain from adding the course; instead, it should update the corresponding entry. 
To append new entries to the subform, you can use the UPDATE Records API. Refer to this kaizen to learn more about manipulating subforms using Zoho CRM APIs. 

Student Performance is a module created for the subform configured in the Student Exams module. In order to perform the PATCH operation with an Update API, make a COQL API call to the Student Performance module and fetch the existing data, if any.  

subform_examMap = Map();
subform_examMap.put("select_query","select Course, Total_Time, Marks from Student_Performance where Parent_Id.id =" + exam_id);
subform_response = invokeurl
[
type :POST
parameters:subform_examMap.toString()
connection:"crm_oauth_connection"
];

This query retrieves the exam records of the student for that particular exam in Student Exams module, from the Student Performance subform. The subform should correspond to the parent record that matches the notification data. Since we already have the ID of that parent record from one of the previous COQL call, we have directly used the response in this query. 

Now that we have the existing subform data, the function has to verify whether the data from webhook call matches any of the Course in the subform data. If it matches, the new entry replaces the existing one; otherwise, the new entry is added to the existing entries and forms a request payload called examinfo. This payload will be used in the later part of the functions to update the record in Student Exams module. 

Following is how you should achieve this using for-each loop. 

final_subform = List();
flag = true;
if(!isBlank(subform_response))
{
subform_data = subform_response.getJSON("data").toList();
if(subform_data.len() > 0)
{
for each  data in subform_data
{
if(data.get("Course").get("id") == course_id)
{
final_subform.add({"Course":{"id":course_id},"Total_Time":time_taken,"Marks":marks});
flag = false;
}
else
{
final_subform.add(data);
}
}
}
}
if(flag || isBlank(subform_response))
{
final_subform.add({"Course":{"id":course_id},"Total_Time":time_taken,"Marks":marks});
}
examinfo = {"Student_Performance":final_subform};

Next, let us update the Student Performance subform in the Student Exams module using the pre-defined integration task called Update Record in Zoho CRM functions. This task makes an Update Records API call to replace all entries within the subform. It updates the entries with the same course_id provided in the notification, inserts new entries and removes old entries accordingly.   

response = zoho.crm.updateRecord("Student_Exams",exam_id,examinfo);
return "nothing";

Save the function and click the more icon of the function you have created and choose REST API.  



Enable the OAuth2 and API Key for the function. 

Next copy the API key and provide it in the webhook URL of the Portal App. 



On receiving notifications to this URL the function will be triggered and the records will be updated. 



We believe you found this post both beneficial and informative!

Your thoughts and perspectives matter to us. If there is a topic you would like us to delve into or if you have any questions, please feel free to drop a comment below or send us an email at support@zohocrm.com.

Stay tuned until we circle back to you on next Friday! 

--------------------------------------------------------------------------------------------------------

Recommended Reads

---------------------------------------------------------------------------------------------------------


    Access your files securely from anywhere



                          Zoho Developer Community




                                                  • Desk Community Learning Series


                                                  • Digest


                                                  • Functions


                                                  • Meetups


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner


                                                  • Word of the Day


                                                  • Ask the Experts





                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator Resources



                                                                                      Zoho CRM Resources

                                                                                      • CRM Community Learning Series

                                                                                        CRM Community Learning Series


                                                                                      • Kaizen

                                                                                        Kaizen

                                                                                      • Functions

                                                                                        Functions

                                                                                      • Meetups

                                                                                        Meetups

                                                                                      • Kbase

                                                                                        Kbase

                                                                                      • Resources

                                                                                        Resources

                                                                                      • Digest

                                                                                        Digest

                                                                                      • CRM Marketplace

                                                                                        CRM Marketplace

                                                                                      • MVP Corner

                                                                                        MVP Corner





                                                                                          Design. Discuss. Deliver.

                                                                                          Create visually engaging stories with Zoho Show.

                                                                                          Get Started Now


                                                                                            Zoho Show Resources


                                                                                              Zoho Writer Writer

                                                                                              Get Started. Write Away!

                                                                                              Writer is a powerful online word processor, designed for collaborative work.

                                                                                                Zoho CRM コンテンツ










                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方




                                                                                                            • Recent Topics

                                                                                                            • Share Projects with Vendor Zoho Projects Portal

                                                                                                              I have a vendor/reseller of my services. They private label my services. My portal is branded. Can an individual project be "shared" or the data sync with another portal? I believe that this can be done with CRM.
                                                                                                            • Zoho Books - Sales Person Information

                                                                                                              Hi Team, On Invoices, Quotes, etc... I can include the Sales Person, but it only shows their name and not their email or phone number. It would be great to have place on invoice templates where we can manage what sales person information should be shows
                                                                                                            • Feature Request – Support for Stripe Direct Debit for Canadian Customers in Zoho Books

                                                                                                              I’d like to request support for Stripe Direct Debit as a payment option for Canadian customers within Zoho Books. Currently, while Stripe credit card payments are supported for Canadian businesses, there is no option to enable Direct Debit (ACH/EFT) through
                                                                                                            • Zoho Desk blank page

                                                                                                              1. Click Access zoho desk on https://www.zoho.com/desk/ 2. It redirects to https://desk.zoho.com/agent?action=CreatePortal and the page is blank. Edge browser Version 131.0.2903.112 (Official build) (arm64) on MacOS
                                                                                                            • Free Plan mail accounts details

                                                                                                              In the zoho mail pricing there's a free plan that includes: FREE PLAN Up to 25 Users 5GB* /User, 25MB Attachment Limit Webmail access only. Single domain hosting. I need to make sure that I'm able to create multiple email accounts in the form of: name@domain.com
                                                                                                            • Timentry and Support Plan Relationship

                                                                                                              Timentry and Support Plan Relationship A customer can buy multiple products and request different SLAs and support plans for each product. We can enter different support plans and define the credit. The scenario I want to happen; - To reduce the credits
                                                                                                            • Repeating Images in Emails

                                                                                                              Some emails have images that are repeated when viewed both on the web client (mail.zoho.com) and when using the Zoho Mail android app. It looks like perhaps some of the email styling is being ignored or applied incorrectly, as a brief inspection of the
                                                                                                            • Issue with ticket replies via Slack: '+' symbols replacing spaces in emails

                                                                                                              Hello, support team! We're experiencing an issue when replying to tickets directly through Slack. When the reply is sent to the email, spaces are being replaced by '+' symbols. This makes the message harder to read and understand. Is there any solution
                                                                                                            • Allow 2 logos for Branding, one for Light Mode and one for Dark Mode?

                                                                                                              Our logo has a lot of black text on it. If we leave the background transparent, per recommendation of Zoho, when a user is viewing a file and turns on dark mode, our logo is not really visible and looks really weird. It would be really great if we could
                                                                                                            • Zoho Creator Populate radio field with values with all the created rows subfor

                                                                                                              I have Main Form where i have a lookup field where i get brewery names and the number of tanks as a multiline text field with a list of beer names Based Brewery selected and bbt_tanks number i create rows in the subform and now i want to populate list
                                                                                                            • Currency column showing $ symbol

                                                                                                              Hello, I'm importing data from Zoho Projects to Zoho Analytics and I was wondering why "Budget amount" column is set in dollars even if the "Currency" column = EUR: Is there a way to get the budget amount as "EUR" + nnnnnn? Thank you
                                                                                                            • Android notifications not working

                                                                                                              I've set push notifications to 'on' in ZohoMail for android settings but nothing doing. Can anyone help? I do use a VPN.
                                                                                                            • my clients are not receiving mails

                                                                                                              Hi, My clients are not receiving my mails sent . may we know the reason My dns server and imap settings are perfect
                                                                                                            • Múltiple Deals when converting a Lead

                                                                                                              Hello!!! I hope someone can help me figure out the best way to handle this scenario. I have a multi-select field named “Service” in the Leads module that captures either Service A, Service B, or both. When converting a lead, Zoho CRM currently creates
                                                                                                            • zoho mail and crm is very slow

                                                                                                              I have recently employed Zoho in our organisation. Even after taking high speed internet, mail and CRM takes many minutes to even load. Its really slow and faces lot of downtime.
                                                                                                            • How to use if_case with expressions other than equals

                                                                                                              I'm trying to define a formula column that implements logic like this case statement would: case when numfld1 is null then null when numfld2 > 0 then 100*numfld2 when numfld2 < 0 then numfld2 else 0.0 end In formula columns, the docs say you need to use
                                                                                                            • Zoho CRM's V8 APIs are here!

                                                                                                              Hello everyone!!! We hope you are all doing well. Announcing Zoho CRM's V8 APIs! Packed with powerful new features to supercharge your developer experience. Let us take a look at what's new in V8 APIs: Get Related Records Count of a Record API: Ever wondered
                                                                                                            • Create global project dashboard for all users

                                                                                                              Would like to be able to create a custom dashboard for projects with certain widgets that are default for all new projects.  right now, I have to modify each project dashboard per project per user.  This is not practical.  
                                                                                                            • What's New in Zoho Inventory | January - March 2025

                                                                                                              Hello users, We are back with exciting new enhancements in Zoho Inventory to make managing your inventory smoother than ever! Check out the latest features for the first quarter of 2025. Watch out for this space for even more updates. Email Insights for
                                                                                                            • Inline images are not shown on iPhone

                                                                                                              When I add an image inline it gets displayed on a Zoho's computer software or web browser, but not on Zoho's iPhone app - the image appears to be broken and cannot be copied neither saved. What's the problem with displaying images inline when reading
                                                                                                            • Kaizen #186 : Client Script Support for Subforms

                                                                                                              Hello everyone! Welcome back to another exciting Kaizen post on Client Script! In this edition, we’re taking a closer look at Client Script Support for Subforms with the help of the following scenario. " Zylker, a manufacturing company, uses the "Orders"
                                                                                                            • Viewing Live data

                                                                                                              Where can I see the live data that is sent from the device?
                                                                                                            • Canvas templates can now be shared with different CRM organizations

                                                                                                              ----------------------------------------Moderated on 14th February, 2023------------------------------------------- Dear all, This feature is now open for all users in all DCs. To learn more about importing and exporting canvas templates, read our help
                                                                                                            • Formatting Mailing Labels

                                                                                                              I want to use the "Print Mailing Labels" function on the drop down list, but I am not seeing a way to change the formatting on the mailing labels. At the moment, the information that appears on the mailing labels ARE NOT mailing addresses, but random information.  I would also like to change be able to change the size of the labels.  At the very least I would like to know what type of labels I can get that would be the correct size.  
                                                                                                            • CRM to Writer Mail Merge Preview not working

                                                                                                              When performing a mail merge from CRM to writer the preview function does not work. I get the following error. I am a Zoho one user on a ChromeOS. I have been successfully using mail merge from CRM to Writer about 4 years. This error seemed to coincide
                                                                                                            • Best practice : when to convert lead to Deal

                                                                                                              Hello, I'm new to Zoho and run my own business. To make sure I'm using Zoho correctly, when do I press convert, from Lead to Deal, at what stage in the conversion funnel/conversation. I want to make sure I can a) monitor status of all pending lead or
                                                                                                            • Show Call History During a Blueprint Transition in Leads Module

                                                                                                              Hi all, I have a Blueprint set up in the Leads module with a transition to Reattempt Call, which updates the lead status to Attempted Contact. I’d like to know if there’s a way to show the call history or at least a summary of how many call attempts have
                                                                                                            • How do I filter contacts by account parameters?

                                                                                                              Need to filter a contact view according to account parameter, eg account type. Without this filter users are overwhelmed with irrelevant contacts. Workaround is to create a custom 'Contact Type' field but this unbearable duplicity as the information already
                                                                                                            • How to delete more than 100 leads at a time.

                                                                                                              We are a call center and we need to upload fresh leads daily.  Is there any way to delete all leads only at once.  Currently we are deleting 100 at a time. Please anyone who can help. Thank you.
                                                                                                            • The Next Chapter for CRM for Everyone: Moving from Early Access to Phased Rollout for Customers

                                                                                                              #CRM25Q1 Hello Everyone, Until now, CRM for Everyone has been available in early access mode exclusively for users who opted to try the new version. We are now transitioning to a phased release, starting with the basic edition. We are thrilled to announce
                                                                                                            • Canvas for related lists

                                                                                                              Hey, we would like to customize our related lists. For us, it would make more sense to present the data from an assigned record vertical instead of horizontal. Can we get a related list Canvas view?
                                                                                                            • Standalone custom function not generating logs

                                                                                                              Why dont't standalone custom functions generate logs when the're called from another function? I have some functions (workflow, buttons and blueprint) that have common parts, so I put that part in a standalone function which is called from the others.
                                                                                                            • Show Zoho Books Retainer Invoice in Zoho CRM

                                                                                                              Hi Support, How can I get Retainer Invoices created in Zoho Books to show in Zoho CRM? If a sales person needs to collect an upfront deposit, they should be able to see that the retainer invoice has been created and paid. Thanks, Ashley
                                                                                                            • Feature Request - Zoho Books - Add Retainer Invoices to CRM/Books integration

                                                                                                              Hi Books Team, My feature request is to include Retainer Invoices in the finance suite integration with Zoho CRM. This way we will be able to see if retainer invoices have been issued and paid. I have also noticed that when the generate retainer invoice
                                                                                                            • ACR Phone mobile app for logging phone calls into Zoho CRM

                                                                                                              ACR Phone is an Android app recording voice calls with additional features such as blacklist, cloud upload, call log and more. Use the ACR Phone extension for Zoho CRM to generate Leads and Contacts with the voice recording attached right after your phone
                                                                                                            • New in Zoho Sign: Allow recipients to review and change associated recipients

                                                                                                              Greetings! We are happy to announce the addition of a new recipient role, Manages recipients, in our signature workflows. This role enables a recipient to review, modify, or add details for any recipients associated with them in the workflow. This ensures
                                                                                                            • How can I throw an error / terminate the flow from within a custom function?

                                                                                                              As the subject says. I would like to be able to terminate a flow from within a custom function if certain conditions are not met. I know I could hook a decision box to the output of my custom function and check return variable, but hoping there is a more
                                                                                                            • Multiple Zoho Attendees in a Customer meeting

                                                                                                              We are having constraints with having to log duplicate meetings when we have 2 Zoho users attending a customer meeting. What are the options to resolve this? You can add participants, but you cannot report on them. What can be done to avoid creating so
                                                                                                            • iOS 18 is here! Discover the enhanced Bigin app with iOS 18, iPadOS 18 and macOS Sequoia.

                                                                                                              Hello, everyone! We are excited to be back with new features and enhancements for the Bigin app. Let us take a look at the new iOS 18 and iPadOS 18 features. The following is the list of features covered in this update: Control widgets. New app icons.
                                                                                                            • Multi-Select lookup field has reached its maximum??

                                                                                                              Hi there, I want to create a multi-select lookup field in a module but I can't select the model I want the relationship to be with from the list. From the help page on this I see that you can only create a max of 2 relationships per module? Is that true?
                                                                                                            • Next Page