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



                                          Zoho Marketing Automation


                                                  Manage your brands on social media



                                                        Zoho TeamInbox Resources

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

                                                                                                  • Leads, Prospects, Contacts, Clients and Me

                                                                                                    I'm trying to adapt my process to Zoho and am getting confused. Here's how I did it before. Maybe it's just terminology...? Leads - anyone from any source that I might want as a client. Leads include people that I am sending emails or tapping in social
                                                                                                  • Contacts, Leads, Prospects, Opportunities, Deals, Oh my!

                                                                                                    I've implemented three CRM's in previous companies, and led the effort for two of those.  I'm pretty familiar with sales pipeline management. For my current company, I chose Zoho One because of the broad range it includes for other business processes, and am generally quite happy.  So now it's time to dig into Zoho CRM And I find myself a bit befuddled. In other implementations, a "Contact" was just that- a name and some contact information.  Could be anybody whether interested in doing business
                                                                                                  • License Issue

                                                                                                    Hello Campaigns Team, we have 17 ZOHO One licenses but in campaigns I get the message that we have a free plan. How can we use ZOHO campaigns? As far as I understood campaigns is a part of ZOHO One. THX Niels
                                                                                                  • Visual Sync Status Indicator

                                                                                                    I think I've see in documentation that WorkDrive had the industry standard of indicating a sync status for individual files and folders. I'm just starting with WD and synced my first test folder, but there was no way to tell what's happening by just looking
                                                                                                  • Is there a way to make the new tab button open a new cloud document?

                                                                                                    I'm coming from Google Docs. Plus, is there any way to have a set a default font? I'm using the desktop app and I prefer the options I can get through the cloud documents. I want the convenience of just opening a new cloud document rather than doc that's
                                                                                                  • Tip 26: How to hide the "Submit" button from a form

                                                                                                    Hi everyone, Hope you're staying safe and working from home. We are, too. By now, we at Zoho are all very much accustomed to the new normal—working remotely. Today, we're back with yet another simple but interesting tip--how to hide the Submit button from your forms. In certain scenarios, you may want to hide the submit button from a form until all the fields are filled in.  Use case In this tip, we'll show you how to hide the Submit button while the user is entering data into the form, and then
                                                                                                  • Trying to export a report to Excel via a deluge script

                                                                                                    I have this code from other posts but it gives me an error of improper statement, due to missing ; at end of line or incomplete expression. Tried lots of variations to no avail. openUrl(https://creatorapp.zoho.com/<username>/<app name>/XLSX/#Report:<reportname>,"same
                                                                                                  • Bigin_Email Notification not being sent when a new lead is created

                                                                                                    I have a workflow in BIGIN set to send an email notification when a new lead is created via a webform (integrated with ZohoForm) The trigger is whenever a contact is "Create or Edit". Conditioning was applied for contacts which source is "Website" If
                                                                                                  • ZOHO CRM API Python SDK Convert Quote to Sales Order

                                                                                                    I can see footprints that this may be possible through Inventory Conversion. But I am unable to locate any specific details or samples on how to do this. I am using the most current Python SDK. Any support or even sample code would be much appreciated
                                                                                                  • Displaying Notes/Description Columns in "All Expense" showing Tabs

                                                                                                    It's surprising to see there is no option to view description columns in tab showing all expenses. There are provisions for Reference# and Status, but why not the description/notes. Please Add. Thank You.
                                                                                                  • Zoho Books - uploading company logo squashed

                                                                                                    I am trying to upload my company logo with the following dimensions - 240 x 240 pixels and a file size of 106Kb. When I look at the logo in my invoices, it is squashed and not the right size. Any idea what is going on? I've tried uploading jpeg and png
                                                                                                  • Petty cash discrepancy

                                                                                                    How do I record a petty cash discrepancy? We had money go missing and need to document that in the books, but I'm not sure how to put that in. It's not an expense, just a loss of cash.
                                                                                                  • Zoho Workdrive file versions

                                                                                                    Hello. I have Workdrive setup to sync files offline to an external hard drive. The off line sync folder currently shows at 1.42 TB. I have a 5 TB storage limit in Workdrive. The cloud version of Workdrive says that I have used all 5 TB! I have 27, 285
                                                                                                  • Integration with Zoho CRM?

                                                                                                    Will it be possible to integrate WorkDrive with CRM similar do Zoho Docs?
                                                                                                  • How to control the # of version of files to keep?

                                                                                                    Currently most of the WorkDrive Storage comprise of the many versions of files saved. How do I save some space and reduce the number of version of date or files saved in WorkDrive? Thanks
                                                                                                  • Should I Use Zoho Mail Calendar, or Zoho CRM Calendar, or Zoho Calendar?

                                                                                                    After a couple of dozens Zoho solopreneur products that I transitioned to after becoming a Zoho One enthusiast 5 years ago, I am finally preparing to conquer the remaining two bastions: Mail and WorkDrive (using Google Workspace at the moment). A NYC
                                                                                                  • Add comments to a form

                                                                                                    Hello, I'm trying to add comments to a form using a subform with one field named comment, but I don't want prior comments to be editable or deleteable by anyone (except the admin).  Is there a way to only display prior comments (with a datetime, user and comment field preferably) but still be able to add new ones when editing the main form?  I'm not tied to subforms if there is an easier was to do this?
                                                                                                  • Zoho Books | Product updates | March 2025

                                                                                                    Hello users, We have rolled out new updates in Zoho Books to enhance your accounting experience. These include the ability to create workflow rules for manual journals and Multi-Factor Authentication (MFA) for customer and vendor portals. Explore these
                                                                                                  • Work Drive Tray Icon Missing

                                                                                                    How can I get the tray icon back? The app froze, had to restart PC and then it's been gone since...  I've re-installed the windows program and restarted my machine twice now.
                                                                                                  • cant receive emails

                                                                                                    I have checked the Dns and everything seems to be fine pls check the print screens attached below help me cause i need to solve this fast
                                                                                                  • Retainer invoice in Zoho Finance modlue

                                                                                                    Hello, Is there a way of creating retainer invoices in the Zoho Finance module? If not can I request this is considered for future updates please.
                                                                                                  • iOS Widget Not Working

                                                                                                    It appears that the iOS widget is not working, displaying a blank white screen instead of a selected note. I’m using app version 6.5.12 and iOS 18.3.1.
                                                                                                  • Two Problems With Data Imported to Notes

                                                                                                    Occasionally I want to create a note by copying and pasting a few paragraphs from an article on line. When I create a new note and paste in the section the newly created note winds up with each paragraph in white text on a dark background rather than
                                                                                                  • Workdrive on Android - Gallery Photo Backups

                                                                                                    Hello, Is there any way of backing up the photos on my android phone directly to a specific folder on Workdrive? Assuming i have the workdrive app installed on the phone in question. Emma
                                                                                                  • Generate a link for Zoho Sign we can copy and use in a separate email

                                                                                                    Please consider adding functionality that would all a user to copy a reminder link so that we can include it in a personalized email instead of sending a Zoho reminder. Or, allow us to customize the reminder email. Use Case: We have clients we need to
                                                                                                  • How to associate a document sent in Zoho Sign with an deal in the CRM?

                                                                                                    Hi, often documents are loaded in Zoho sign and sent for signature. These sometimes are linked to a deal in the Zoho CRM and would be nice to see the status of the document within the CRM. I am aware of the integration, but that assumes that the document
                                                                                                  • Preventing auto-redirect to Parent Record on Save...

                                                                                                    Our users often create records from the related list on th left side of the screen. They click the blue "plus" button to create the record. This is handy, but for some modules, or situations, they would like to remain on the record AFTER clicking "Save",
                                                                                                  • CRM Portal Help

                                                                                                    Hello, I am trying to set up a portal to connect with our referring doctors to keep patient cases organized. I set up the accounts module as office, the contacts as doctors, the leads as patients, and the deals as treatments. Everything seems to work
                                                                                                  • Zoho Books (UK) needs to be able to submit a CT600 CTSA return

                                                                                                    As well as a VAT Return, most (if not all) small businesses have to submit a CT600 Corporation Tax Self-Assessment. There are many providers who do this (like Xero) bujt not Zoho. Can you add this to the request list please? Many thanks Steve
                                                                                                  • No image image comes out in the recipient when I sent an email

                                                                                                    Hello to the entire forum, when I send an email from Zoho, my profile picture does not come out. On the other hand, if you do, using Gmail accounts. How is it configured to leave ??? Thank you Greetings !!
                                                                                                  • Zoho Desk & Tasks

                                                                                                    Hi, I'd like to be able to create a set of tasks each time a customer request comes in, as I understand it, currently each would need to be create manually. Project is too much of an overhead for what we want to use. Effectively in various use cases we
                                                                                                  • zet pack not working

                                                                                                    We are using the zet pack command to package our Zoho extension. However, after running the command, the extension gets packed, but the resulting package is empty. We've attached a screenshot for reference. Could you please assist us with resolving this
                                                                                                  • While retrieving the Balance Sheet Report, there is always this "COST OF GOODS SOLD", This is not editable.

                                                                                                    Hi Zoho & Readers, While retrieving the Balance Sheet Report, there is always this "COST OF GOODS SOLD", which is reduced from the Sales to arrive at the gross profit. The issue I face here is that Service Oriented Companies don't incur any COGS, hence
                                                                                                  • Changing salesorder_number via zoho flow

                                                                                                    For some reason updating salesorder_number via zoho flow does not stick. Flow is triggered by new sales order filtered by sales channel update sales order: PO#: CX${trigger.reference_number} Salesorder_number: CX${trigger.reference_number} PO# successfully
                                                                                                  • Working with Products that are non-tangible

                                                                                                    How does one create a 'service' in products? Is there a way to disable inventory functions for things like Sofware as a service? The services module doesn't look to be much help either. Not sure how to do this in CRM
                                                                                                  • Loop in Blueprint but it works. Why? How should this be set?

                                                                                                    see picture
                                                                                                  • Zoho Error: This Operation has been restricted. Please contact support-as@zohocorp.com for further details

                                                                                                    Hello There, l tried to verify my domain (florindagoreti.com.br) and its shows this error: This Operation has been restricted. Please contact support-as@zohocorp.com for further details. Screenshot Given Below -  please check what went wrong. Thanks
                                                                                                  • Bulk Delete Images

                                                                                                    How do I bulk Delete Images from Zoho Campaigns. We have been using the Zoho since 2019 and can still only see the option to delete images one by one and we have a lot of old Campaign imagery we don't need anymore. Thanks!
                                                                                                  • Tip #5: Setting access rights at the subfolder level

                                                                                                    Hello everyone, We hope you're finding our WorkDrive Tips and Tricks series useful. For today's tip, we'll teach you how to assign higher subfolder permissions to Team Folder members. Team Folders helps you avoid the drawbacks of traditional file sharing.
                                                                                                  • I want to update the photo from the mobile app to the product tab product.

                                                                                                    I want to update the photo from the mobile app to the product tab product. Because I want to use the CRM product tab for inventory management Contact registration can save photos from the mobile app. Attached screenshot.
                                                                                                  • Next Page