Concatenate two fields into a single one.

 

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-requisites:

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 function:

  1. Go to Setup > Automations > Actions > Functions > Configure Function > Write your own.
  2. Provide a name for the function. For example: "Merge fields - Concatenate".
  3. Select the moduleto be associated as Leads. Add a description(optional).
  4. Copy the code given below.
  5. Click "Edit arguments".
  6. Enter the name as "leadId" and select the value as "Lead Id".
  7. Click Save & Execute Script.
  8. Save the changes.

 

The Code:

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".

For v2 Editor - DRE:

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("Field_Name",name);
update = zoho.crm.update("Leads",leadId.toLong(),mp);
info mp;
info update;

For V1 Editor:

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:

  • The code is zoho.crm._getRecordById for Version 1.0 of APIs.
  • 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 us know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!

Return to Tips