Take a case of leads captured through web-forms. Most leads don't fill out the entire form. Once the lead is prospected, you go on to create relevant records in contact and accounts module. Now that you qualified the leads, you don't want to miss out on an opportunity to collect more details, do you? When you update these details in the accounts module, you'd want these to be automatically updated in the contacts module as well. This week's custom function helps in doing just that.
And it isn't just the Contacts module that gets updated. The related fields in any selected module, including custom modules, is auto-updated using this custom function. To apply this custom function to other modules, simply update the module names and ID in the code.
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: “Auto-update related fields”.
- Select the module as Accounts. Add a description(optional).
- Copy the code given below.
- Click “ Edit arguments ”.
- Enter the name as “accountId” and select the value as “Account Id”.
- Save the changes.
The script:
Code for Version 2.0 API:
relatedcontacts = zoho.crm.getRelatedRecords("Contacts", ("Accounts"), accountId.toLong());
//info relatedcontacts;
for each ele in relatedcontacts
{
mp=map();
mp.put("Contact_Type", input.type );
update = zoho.crm.update("Contacts", ele.get("id"), mp);
info mp;
info update;
}
Code for Version 1.0 API:
accountIdStr=input.accountId.to.String();
relatedcontacts = zoho.crm.getRelatedRecords("Contacts", ("Accounts"), accountIdStr);
info relatedcontacts;
for each ele in relatedcontacts
{
contactId = ifnull(ele.get("CONTACTID"),"");
mp=map();
mp.put("Contact Type", input.type );
update = zoho.crm.updateRecord("Contacts", contactId, mp);
info mp;
info update;
}
Check this one out and let me know how it works! If you have questions, ask away. Share this with your team if you find it useful. See you all next week with another interesting custom function. Until then!