Businesses often collect information like a product's serial number, vehicle identification number (VIN), ISBNs for books, or credit card numbers, consisting of a series of numeric or alphanumeric characters. This data must be entered in a specific pattern for processing and validation in the backend systems, such as 123 456 7890. Although a single line, number, or long integer field with a tooltip and criteria-based validation rule can partially ensure correct formatting, it is not entirely foolproof. An incorrect data format can impede the efficiency of automated processes, resulting in disruptions and errors. This is where our low-code tools can be valuable.
Using custom functions, you can automatically format the data entered in your CRM to meet the required structure when creating a contact record. This approach helps preserve data integrity and saves time by ensuring consistent entry of field data in the necessary format. Continue reading to learn more.
Permissions and availability
- Users with the Modules Customization permission can add custom fields.
- Users with the Manage Automation permission can create and update workflow rules.
- Users with the Manage Extensibility permission can create custom functions.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Add a Single Line field in the Contacts module. The field will hold the serial number entered by your customers. Learn more
- Create a workflow rule for the Contacts module that triggers every time a contact is created in your CRM. Learn more
- Write a custom Deluge function that formats the serial number field and link it with the workflow rule. Learn more
- Test the workflow rule in a sandbox before deploying it to your production environment. Learn more
Add a custom field
The first step is to add the custom Single Line field to the Contacts module.
- Navigate to Setup > Customization > Modules and Fields.
- Click the Contacts module to open the layout editor.
- Drag and drop the Single Line field from the New Fields tray to the desired section of the layout.
- Name the single line field (e.g., "Serial Number") and define its properties as required.
- Once you've finished, click Save and Close.
Create a workflow rule
The next step is to create a workflow rule in your CRM account.
- Navigate to Setup > Workflow Rules > +Create Rule.
- Select Contacts from the module dropdown list.
- Provide a name for the rule. For example: "Format serial number".
- Add a description (optional), then click Next.
- In the Execute this workflow rule based on section, choose Record Action, then select Create from the dropdown and click Next.
- In the Which contacts would you like to apply the rule to? section, select All Contacts and click Next.
- Under Instant Actions, select Function and Write your own.
- Provide a name for the function, as well as a description, if necessary.
- On the Deluge Script Editor, do the following:
- Copy and paste the code provided below.
- Click Edit Arguments.
- Choose Contacts - Contact Id, then name it contId.
- Click the + icon to add more arguments.
- Choose Contacts - Serial Number, name it number, and then click Save.
- Click Save & Execute Script.
- Click Save on the workflow rule page.
The code
Serial_Number = number;
new = number.subString(0,3) + " " + number.subString(3,6) + " " + number.subString(6,9) + " " + number.subString(9);
info "new : " + new;
mp = Map();
mp.put("Serial_Number",new);
info "map : " + mp;
update = zoho.crm.updateRecord("Contacts",contId,mp);
info update;
Notes
- The code above will transform a numeric serial number of the value "123456789012345" into the pattern "123 456 789 012345". You can customize this to match your preferred format by modifying the code.
- Make sure to use the accurate API names for their corresponding fields in the code snippet (e.g., Serial Number). Learn more
- The solution is an example of formatting the serial number in a custom single-line field of a contact record during its creation. You can use this code for any other module, such as leads, by modifying the module name and parameters.
Test the solution
- Navigate to Contacts > Create Contact.
- On the Contact Details page, enter the required contact information, including the serial number, and then click Save.
The workflow rule will be triggered. - Check whether the contact's serial number was formatted as specified in the code snippet.
Tip
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Idea
If you want your customers to enter the serial number in the intended pattern without it being automatically formatted after saving the record, you can achieve this by using a validation rule. Simply use the following code snippet to create a validation rule that only accepts serial numbers that follow the specified pattern.
entityMap = crmAPIRequest.toMap().get("record");
num = entityMap.get("Serial_Number");
if(!num.isNull())
{
n1 = num.toList(" ");
digit = {3,3,3,5};
c = 0;
numberbol = true;
dig = true;
for each n in n1
{
alen = digit.get(c);
if(n.isNumber() == false)
{
numberbol = false;
}
s = n.toString().length();
if(s != alen)
{
dig = false;
}
c= c +1;
}
response = Map();
if( dig == false || numberbol == false)
{
response.put('status','error');
response.put('message','Invalid format');
}
else
{
response.put('status','success');
}
}
else
{
response.put('status','success');
}
return response;
Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.
More info
- ModuleContacts
- Trigger PointWorkflow Rule
- EditionEnterprise and above
- ComplexityMedium
- Implementation Time30 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST