Some businesses may want to add a specific subform in multiple modules. For example, an automotive repair shop would like to display the parts purchased by their customers within a subform in both the Accounts and Orders modules. Each part can have its specifications captured in this subform, while a lookup field facilitates the connection between the two modules. This setup enables salespeople to cross-reference and seamlessly view all parts associated with an account, and vice versa.
However, what if they want to update subform data automatically from the Accounts to the Orders module? This is where a custom function becomes invaluable, particularly when there's a lookup field in the accounts module.
If your business follows this practice, you must set up a workflow rule that triggers whenever an account is created or modified. Once you create it, connect it to a custom function that automatically copies the subform data from the Accounts module to the Orders module. For further details, refer to the sections below.
Permissions and availability
- Users with the Manage Extensibility permission can create connections and write custom functions.
- Users with the Modules Customization permission can add custom fields.
- Users with the Manage Automation permission can create and update workflow rules.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Create a Zoho OAuth connection with the required scopes for your Zoho CRM account, as detailed in the "Create Connection" section below. Learn more
- Add a Lookup field in the Accounts module. This is where you link an account with the parts they have purchased or ordered. Learn more
- Create a workflow rule for the Accounts module that will trigger a custom function whenever an account is created or edited. Learn more
- Write a custom Deluge function that updates subform information in connected records from the Accounts to the Orders module. Learn more
- Test the workflow rule in a sandbox before deploying it to your production environment. Learn more
Create a connection
The first step is to create an OAuth connection in your Zoho CRM account.
- Go to Setup > Developer Space > Connections.
- Click Create Connection.
- Select Zoho OAuth under Default Services.
- Specify a Connection Name.
You must enter this name in the code snippet below. - Select the following Scopes to request access:
- ZohoCRM.modules.all
- Click Create and Connect.
- Click Connect, then click Accept to confirm authorization of access for the scope requested by the client.
Add a custom field
The next step is to add a custom lookup field to the Accounts module.
- Navigate to Setup > Customization > Modules and Fields.
- Click the Accounts module to open the layout editor.
- Drag and drop the Lookup field from the New Fields tray to the desired section of the layout.
- Name the lookup field (e.g. "Order").
- Select the lookup module (e.g. "Orders") from the drop-down menu.
- Enter the title (e.g. "Part Accounts") for the related list in the lookup module, and click Done.
- Once you have finished, click Save and Close.
Create a workflow rule
The final step is to add a workflow rule that triggers upon creating or editing an account.
- Navigate to Setup > Workflow Rules > +Create Rule.
- Select the Module as Accounts from the drop-down list.
- Provide a name for the rule. For example: "Copy subform data to orders".
- Add a description, if required, then click Next.
- In the Execute this workflow rule based on section, do the following:
- Choose Record Action, then select Create or Edit from the drop-down.
- Check the box for Repeat this workflow whenever an Account is edited.
- Click Next.
- In the Which accounts would you like to apply the rule to? section, select All Accounts, then click Next.
- Under Instant Actions, select Function and Write your own.
- Provide a Name for the function, as well as a description, if necessary.
- On the Deluge Script Editor, do the following:
- Copy and paste the code given below.
- Click Edit Arguments.
- Choose Accounts - Account Id, then name it acctId.
- Click the + icon to add more arguments.
- Choose Order - Order Id, name it pId, then click Save.
- Click Save & Execute script.
- Click Save on the workflow rule page.
The code
rsp = zoho.crm.getRecordById("Accounts",acctId);
sub1 = rsp.get("Parts_Information");
ls = list();
for each ele in sub1
{
mp = Map();
mp.put("Part_Name",ifnull(ele.get("Part_Name"),""));
mp.put("Part_Number",ifnull(ele.get("Part_Number"),""));
mp.put("Part_Cost",ifnull(ele.get("Part_Cost"),""));
ls.add(mp);
info "mp" + mp;
}
mp1 = Map();
mp1.put("Parts",ls);
datalist = List();
datalist.add(mp1);
param = Map();
param.put("data",datalist);
up = invokeurl
[
url :"https://www.zohoapis.com/crm/v6/Orders/" + pId
type :PUT
parameters:param.toString()
connection:"connectionname"
];
info "up->" + up;
Notes
- Replace "Parts_Information" with the API name of the subform field in the Accounts module.
- Replace "Parts" with the API name of the subform field in the Lookup module.
- Replace "connectionname" with the name of the connection you specified when creating it (see the "Create a connection" section above).
- Part_Name, Part_Number, and Part_Cost are the subform fields in both modules. Replace them with the corresponding field names in your CRM. Additionally, you can add more rows for any additional fields if necessary.
- Make sure to use the accurate API names for their corresponding fields in the code snippet.
Tip
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Click the Accounts tab.
- Open the account record whose subform data you want to copy to a record in the Orders module.
If necessary, create a new account and associate an order. - Click the Edit button.
- Choose the order you want to associate with the account from the lookup field.
- In the Parts Information subform, enter the Part Name, Part Number, and Part Cost, then click Save.
The workflow rule will be triggered. - Check whether the data from the subform fields were copied to the corresponding subform fields in the order record associated with the account.
Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.
More info
- ModuleAccounts
- Trigger PointWorkflow Rule
- EditionEnterprise and above
- ComplexityHigh
- Implementation Time60 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST