
Hello Everyone, This week, we present to you a custom function, which allows you to split the first and last names from the user's email ID based on the separator used in the ID.
Having grown into a large firm, Zylker Techfix aims to optimize its processes, data management, and organization. By default, contacts are created by extracting the customers' names from the email addresses and saving them in the "Last Name" field in the Customers' module.

To create an organized directory, Zylker Techfix wanted to separate the first and last names from the email address using the (.) separator in the email ID.
This custom function allowed them to achieve this with their contacts. Now, you can organize your contacts within Zoho Desk too.
Follow the steps below to configure the custom function within the workflow rule.
Prerequisites
1. Create a connection.
1.1 Go to Setup(S) and choose Connections under Developer Space.
1.2 Click Create Connection.
1.3 Select Zoho OAuth under Default Connection.
1.4 Set the connection name as deskcontact.
1.5 Disable the toggle for User Credentials of Login User.
1.6 Under Scope, choose the below scope values:
Desk.contacts.UPDATE
Desk.contacts.READ
1.7 Click Create and Connect.
1.8 Click Connect and click Accept.
Connection is created successfully.
Create a Workflow Rule
1. Go to Setup(S), choose Workflows under Automation.
2. Under Workflows, click Create Rule.
In the Basic Information section,
3. Select Contacts from the drop-down menu under Module.
4. Enter a Rule Name and Description for the rule.
5. If you want to activate the rule right away, select the Active checkbox. Else, create the rule and activate it later.
6. Click Next.
In the Execute on section, follow these steps:
7. Select Create.
8. Click Next.
9. In the Criteria section, add criteria if required. click Next.
10. In the Actions section, click the + icon and select New next to Custom Functions.
11. Under Basic Information, enter Name and Description for the custom function. Choose Contacts under Module.
12. Under Argument Mapping, give a desired Method Name. Map the arguments as below:
12.1 In the Argument Name field, type contactId and select Contact ID under the Contacts Section.
13. In the script window, insert the Custom Function given below:
- //------------- User Inputs ----------
- orgId = "60xxxxxxxx0"; //replace with your Org ID
- operator = ".";
- //---------------------------------
- logs = Map();
- try {
- contacts = zoho.desk.getRecordById(orgId,"contacts",contactId, "deskcontact");
- firstName = contacts.get("firstName");
- lastName = contacts.get("lastName");
- if(lastName.contains(operator))
- {
- if(operator.contains(".")){
- lastName = lastName.subString(0,lastName.indexOf("@"));
- }
- firstName = lastName.subString(0,lastName.indexOf(operator)).trim();
- lastName = lastName.subString(lastName.indexOf(operator) + 1);
- updateContact = zoho.desk.update(orgId,"contacts",contactId,{"firstName":firstName,"lastName":lastName},"deskcontact");
- }
- }
- catch (errorInfo)
- {
- logs.insert("errorInfo":errorInfo);
- }
- info "logs: \n" + logs;
- if(logs.containKey("errorInfo"))
- {
- throws "Error happen in the CF execution";
- }
NOTE
a. In Line 2, Enter your OrgId with " ".
To access OrgId, go to Setup (S) >> Developer Space >> APIs >> API Authentication.
14. Click Save to save the custom function.
15. Click Save again to save the workflow.
Context
Once configured, this function splits the first and last names for incoming new contacts. This custom function applies to new contacts and new incoming tickets.
We hope this custom function helps you manage your contacts efficiently. Share your feedback and connect with us for more tips and insights.
See you next week!
Regards,
Lydia | Zoho Desk