Business scenario:
Web forms is one of the easiest ways to generate leads in most organizations. Be it an access form that lets prospects watch an on-demand webinar, or a 'Contact us' form that a prospect fills out to reach you, this is one activity that you cannot do away with. However, not all prospects fill out the complete details, do they? Zoho CRM's Phonebridge support lets you make direct calls from within the CRM. This week's custom function saves you the pain of having to edit the record manually to update the country code.
Add this custom function to any module including the custom ones. Change the module name and field names in the code and add the function to the module.
Getting started with the custom function:
Lets assume an example where you add the country code +91(India) to records in the Leads and Contacts module.
For the Lead module:
- Go to Setup > Automations > Actions > Custom Functions > Configure Custom Function > Write your own .
- Provide a name for the custom function. For example: “Add Country code-1”. Add a description(optional).
- Select the module as Leads . Add a description(optional).
- Click “ Free flow scripting ”.
- Copy the code given below.
- Click “ Edit arguments ”.
- Enter the name as “ leadId ” and select the value as “ Lead Id ”.
- Save the changes.
For the Contacts module:
- Go to Setup > Automations > Actions > Custom Functions > Configure Custom Function > Write your own.
- Provide a name for the custom function. For example: “Add Country code-2”. Add a description(optional).
- Select the module as Contacts . Add a description(optional).
- Click “ Free flow scripting ”.
- Copy the code given below.
- Click “ Edit arguments ”.
- Enter the name as “ contactId ” and select the value as “ Contact Id ”.
- Save the changes.
The script:
Code for Version 2.0 API:
For the Leads module:
leadDetails = zoho.crm.getRecordById("Leads", input.leadId.toLong());
mobile = ifnull(leadDetails.get("Mobile"),"");
phone = ifnull(leadDetails.get("Phone"),"");
mp = map();
mp.put("Mobile", "+91" + mobile);
mp.put("Phone", "+91" + phone);
update = zoho.crm.update("Leads", leadId.toLong(), mp);
info update;
info mp;
For the Contacts module:
acctDetails = zoho.crm.getRecordById(("Contacts"), input. contactId.toLong());
phone = ifnull(acctDetails.get("Phone"),"");
fax = ifnull(acctDetails.get("Fax"),"");
mp = map();
mp.put("Phone", "+91" + phone);
mp.put("Fax", "+91" + fax);
update = zoho.crm.update(("Contacts"), contId.toLong(), mp);
info update;
info mp;
Code for Version 1.0 API:
For the Leads module:
leadIdStr = input.leadId.toString();
leadDetails = zoho.crm.getRecordById("Leads", input.leadId);
mobile = ifnull(leadDetails.get("Mobile"),"");
phone = ifnull(leadDetails.get("Phone"),"");
mp = map();
mp.put("Mobile", "+91" + mobile);
mp.put("Phone", "+91" + phone);
update = zoho.crm.updateRecord("Leads", leadIdStr, mp);
info update;
info mp;
For the Contacts module:
contIdStr = input.contactId.toString();
acctDetails = zoho.crm.getRecordById(("Contacts"), input. contactId);
phone = ifnull(acctDetails.get("Phone"),"");
fax = ifnull(acctDetails.get("Fax"),"");
mp = map();
mp.put("Phone", "+91" + phone);
mp.put("Fax", "+91" + fax);
update = zoho.crm.updateRecord(("Contacts"), contIdStr, mp);
info update;
info mp;
Note:
- Change the country code from +91 to any preferred country code in the code.
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.