Welcome back everyone!
Last week, we saw how to
create a Purchase Order from a Quote. This week, let's look at a function that lets you add subform records easily by having the records from other modules as a lookup field within a subform.
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.
Business scenario:
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 week's 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 custom function:
- Go to Setup > Automation > Actions > Functions > Configure Function > Write your own.
- Provide a name for the function. For example: "Product subform update in Deal". Add a description(optional).
- Copy the code given below.
- Click “Edit arguments”.
- Enter the name as “dealId” and select the value as “Deal Id”.
- Click Save&Execute Script to check the code.
- Save the function.
The Code:
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;
Note:
The code given above works only for V2 version of Zoho APIs. Please note that the code WILL NOT work for Version 1.0 APIs.
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 me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful. Do check out other custom functions shared in this
series here.
See you all next week with another interesting custom function. Ciao!