Welcome back everyone!
Business scenario:
It isn't strange to have multiple branches in a business. Or having contacts with multiple branches of the same company. Either way, it would be better to have multiple member accounts for easier identification rather than have all contacts under a single account and lose track of who to contact in which branch. Zoho CRM facilitates the creation of multiple branch accounts (named 'member accounts') which are linked to a parent account.
As useful as this is, if there are any changes made to a parent account. Say, for instance, change of websites, social media pages, activities, deals, etc, then there lies the task of updating each member account manually once again. The process is repetitive. To spare you the effort of manual work, this custom function automates the process by updating the member accounts simultaneously when the parent account is updated.
Getting started with the custom function:
- Go to Setup > Automations > Actions > Custom Functions > Configure Custom Function > Write your own .
- Provide a name for the custom function. For example: “Update member accounts”. Add a description(optional).
- Select the module as Accounts . Add a description(optional).
- Click “ Free flow scripting ”.
- Copy the code given below.
- Click “ Edit arguments ”.
- Enter the name as “ parentaccId ” and select the value as “ Account ID ”.
- Add a new argument with the name as " parentownerId " and select the value as " Account Owner ID ".
- Save the changes.
- Use the custom function in conjunction with a Workflow rule to enable auto-update of member accounts.
The script:
Code for Version 2.0 API:
relatedaccount = zoho.crm.getRelatedRecords("Child_Accounts", "Accounts", parentacctId.toLong());
//info relatedaccount.size();
//info relatedaccount;
for each ele in relatedaccount
{
mp=map();
mp.put("Owner",input.parentownerId);
update = zoho.crm.update("Accounts", ele.get("id").toLong(), mp);
info mp;
info update;
}
Code for Version 1.0 API:
parentacctIdStr = input.parentacctId.toString();
relatedaccount = zoho.crm.getRelatedRecords("Accounts", "Accounts", parentacctIdStr);
info relatedaccount.size();
for each ele in relatedaccount
{
acctid = ele.get("ACCOUNTID");
mp=map();
mp.put("SMOWNERID",input.parentownerId);
update = zoho.crm.updateRecord("Accounts", acctid, mp);
info mp;
info update;
}
-----------------------------------------------------------------------------------------------------------------------------------------------
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!
Update: As you must be aware, API V1.0 will be deprecated and support for version 1.0 API will be available only till Dec 31, 2018. Version 1.0 compatible Functions will continue to work until Dec 31, 2019. You're advised to migrated to API Version 2.0 at the earliest. Check this announcement for more. We've updated the post to include the Version 2.0 compatible Function.