Welcome back everyone!
Business scenario:
Leads are acquired from a variety of sources. Trade fairs, web-forms, referrals, etc are some of the sources. However, you don't get the complete information about a lead at the start. That aside, how will you fill up fields when you don't have the information?
Let us take an example of concatenation of the first and last name fields and displaying the result in a custom field 'Full name'. For instance, if the First name is "David" and the last name is "Chester", the Full name field would be "David Chester". This function applies only if the field is 'not mandatory'. It takes effect only after the lead is saved.
This function is a versatile one, which you can use for merging and updating two fields into a single one on any module. The rest is up to your imagination.
Pre-requisite:
You need to create a custom field named "Full name". This field is not normally available in the record creation form.
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: “Merge fields”. 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.
The script:
Code for Version 2.0 API:
This code is for the example of merging the first and last names of the lead and updating the result in the custom field "Lead_Full_Name" custom field.
leadDetails = zoho.crm.getRecordById("Leads", input.leadId.toLong());
first = ifnull(leadDetails.get("First_Name"),"");
last = ifnull(leadDetails.get("Last_Name"),"");
if ( first != "")
{
name = first + " " + last ;
}
else
{
name = last ;
}
mp=map();
mp.put("Lead_Full_Name",name);
update = zoho.crm.update("Leads",leadId.toLong(),mp);
info mp;
info update;
Code for Version 1.0 API:
This code is for the example of merging the first and last names of the lead and updating the result in the custom field "Full name" custom field.
leadIdStr=input.leadId.toString();
leadDetails = zoho.crm.getRecordById("Leads", input.leadId);
first = ifnull(leadDetails.get("First Name"),"");
last = ifnull(leadDetails.get("Last Name"),"");
if ( first != "")
{
name = first + " " + last ;
}
else
{
name = last ;
}
mp=map();
mp.put("Full Name",name);
update = zoho.crm.updateRecord("Leads",leadIdStr,mp);
info mp;
info update;
Note:
- You can modify the code to make it work in any modules. Change the name of the module from 'Leads' to whichever module you prefer and update the code accordingly.
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 serieshere.
See you all next week with another interesting custom function. Ciao!