There are times when it is necessary to combine two separate field values into a single field. In such instances, we can concatenate two separate fields from the same module with the use of a custom function. For example, in one of the modules, we might want to concatenate First and Last names and display them as a single field called Name. This is just an example; you may apply the same custom function to any two fields you like.
Create a field that displays the concatenated result. This field is not available by default so you have to add it to the page layout manually.
Go to Set Up > Modules and fields > Select the required module > Choose the layout you need to edit.
To create a custom function :
- Go to Setup > Actions > Functions > Configure Function > Write your own
- Provide a Function name, Display name and select the module as per required.
- Click on edit arguments, and map the required arguments. In this case, Lead ID, Lead first name and last name are required.
- Type the below given script and save.
leadDet = zoho.crm.getRecordById("Leads",Lead_id);
map = Map();
map.put("Name1",Lead_first_name + ' ' + Lead_last_name);
con = zoho.crm.updateRecord("Leads",Lead_id.tolong(),map);
Adding the custom function to workflow :
The key benefit of including a custom function in a workflow is that it can be utilized for any module. We integrate workflow rules, as well as any additional buttons and links, into every custom function we design.
- Go to Set Up > Automation > Workflow rules > +Create Rule.
- Enter the required details and select the desired module.
- Select "On a record action" in the "When do you want to execute this rule?".
- Select "Create".
- Select the Condition as "All Leads".
- Choose "Function" from Instant Actions.
- Choose the desired function created by the user and click 'Associate'. In this the case the function name 'Concatenate'.
- Click Save.
Fill out the form with all of the required information. When a new record is produced, the workflow rule is invoked. You can now check the leads module, and the results will be reflected. The 'Name' field combines the first and last name fields.
Other examples :
This custom function can also be used to concatenate additional fields.
1) For example, creating a title based on any of the other parameters. More than two fields can also be concatenated. In this case, a design firm follows a typical naming convention for a field called "Title". This includes their first name, company name, and the service (design) they selected. Fill up the required information. The title field has been left blank since it will be filled in automatically using the required fields.
2) Consider an educational institution that keeps track of student and staff information. The student's name and graduation year are required fields on the application. They usually pertain to different fields. What if the institute insists on having both displayed in the same field? In addition, the institute wants that field to appear in the business card view. This concatenate custom function can also handle this type of case.
Step 1 : Create fields accordingly, in this case 'Year of Graduation' field is added.
Step 2 : Write custom function that concatenate both the fields. Add the created function to workflow rules. Create a new field 'Students detail' which will display the concatenated result.
Stud_yop = zoho.crm.getRecordById("Contacts",cont_id);
map = Map();
map.put("Student_details",cont_name + ' ' + cont_yop);
yop = zoho.crm.updateRecord("Contacts",cont_id.tolong(),map);
Step 3 : Add the result field 'Student details' in business card view.
Step 4 : Create workflow rules for the function.
Note : We can also add 'last name' in the concatenation.