What are subforms?
Explaining plainly, a subform is simply a form within a form. Since all the data stored within your CRM is inter-dependent, there is a need to associate multiple items/records to a single record. To learn more about subforms, click here. This feature is available only in the Enterprise edition.
For example, let's take a situation where you have a client "SHIELD Health Care", and they procure the products "Syringes", "Bandages" and "Gloves" from you. The information about their company would be in Accounts module and the products in Products module. You can create a subform in the Accounts module which can contain the list of products involved in the deal.
Subforms are quite an advancement in the Zoho CRM experience. Simply because of the fact that it solves the problem of establishing a one-to-many relationship with data in your CRM, in which many secondary items are associated to a single primary record.
This function is about using the subform feature. You can associate multiple records with a single record and also have them updated. In this function, we have created a subform in a Deal record which gets information from records in the Products module.
Getting started with the function:
- Go to Setup > Developer Space > Functions > + Create New Function.
- Select Automation as Function type and click Next.
- Provide a name for the function. Add a description(optional).
- Copy the code given below.
- Click Edit Arguments.
- Enter the name as dealId and select the type as Int.
- Click Save&Execute Script.
- Click Save.
dealDetails = zoho.crm.getRecordById("Deals", input.dealId.toLong()); //info leadDetails; subform1 = ifnull(dealDetails.get("Subform_1"),"").toMap(); productId = ifnull(subform1.get("Product"),"").get("id"); productDetails = zoho.crm.getRecordById("Products",productId.toLong()); unitprice = ifnull(productDetails.get("Unit_Price"),"0.0").toDecimal(); subform1id = ifnull(subform1.get("id"),""); subform = Map(); subform.put("id",subform1id); subform.put("Unit_Price",unitprice); sub_forms = List(); sub_forms.add(subform); parammap = Map(); parammap.put("Subform_1",sub_forms); update = zoho.crm.update("Deals",dealId.toLong(),parammap); info parammap; info update;
- The above code works only for API V2.0 and not the previous version.
- Use this code to update a subform in any module, which has records from other modules as a lookup.
Found this useful? Try it out and let us know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!