Businesses often need to know the age of their customers for personalized marketing, targeted messaging, age-specific offers, demographic analysis, and other specific operational needs. The most common method for calculating age is using a formula on the value entered in the date of birth field. However, this method only provides a static age that updates when the controlling field is updated, making it less useful for dynamic age computation. Is there a workaround to automatically calculate and update the current age of a contact? Well, it's just a function away.
Using a combination of a custom field, deluge script, and a schedule, you can automatically compute the age of your contacts daily and whenever a contact is created/edited. The daily computation ensures that you always see the exact age irrespective of whether the date of birth is near or far from the current date. Read on to learn more.
Permissions and availability
- Users with the Modules Customization permission can add custom fields.
- Users with the Manage Views permission can create custom list views.
- Users with the Manage Automation permission can create and update schedules.
- Users with the Manage Extensibility permission can write custom functions.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Add a Formula field in the Contacts module. This field will hold the age in years. Learn more
- Create a custom list view that lists the contact records whose ages need to be auto-updated. Learn more
- Create a new daily schedule to run at 12 AM and link it to the custom function. Learn more
- Write a custom Deluge function that automatically updates age based on the current (today's) date. Learn more
- Test the schedule in a sandbox before deploying it in your production environment. Learn more
Add a custom field
The first step is to add the custom formula 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 Formula field from the New Fields tray to the layout.
- In the Formula Properties window, do the following:
- Enter the Field Label (e.g., "Age").
- Select Decimal as the Formula Return Type from the drop-down list.
- Enter 0 as the value for the Number of decimal places.
- Copy and paste the following formula into the Formula Expression box.
- Floor(Datecomp(Now(),${Contacts.Date of Birth})/1440/365.25) - Click Check Syntax to verify the construction of the formula.
- Click Done.
- Once you have finished, click Save and Close.
Create a custom list view
The next step is to create a custom list view that lists the contacts whose ages need to be auto-updated.
- Click the Contacts Tab.
- In the Contacts Home page, move your mouse pointer to the list view's drop-down.
- Click the New Custom View link and do the following:
- Enter a name for the custom view. (e.g. "Contacts with Age")
- Specify the criteria as "<"<Age> <is not empty> = ${NOTEMPTY}".
- Select the columns to be displayed in the view.
- Choose who can see this custom view.
- Click Save and copy the view's ID from the address bar, which you must enter in the code snippet below.
Create a schedule
The final step is to create a new schedule in your CRM account.
- Navigate to Setup > Automation > Schedules > +Create New Schedule.
- Provide a name for the schedule. For example: "Update contact age".
- Click Add Description and enter a description if necessary.
- In the Function to be executed field, choose Writing Function.
- In the Create New Function window, do the following:
- Provide a name, display name, and description, if necessary, for the function.
- Select Deluge as the Language, then click Create.
- In the Deluge Script Editor, do the following:
- Copy and paste the code provided below.
- Click Save.
- Choose an Execution Start Date and time for the function to be executed.
- Choose the schedule frequency as Every day in the Frequency field.
- Click Save on the schedule page.
The code
list = {1,2,3,4,5,6,7,8,9,10};
for each ele in list
{
resp = zoho.crm.getRecords("Contacts",ele,200,{"cvid":xxxxx});
for each ele in resp
{
contactid = ele.get("id");
dateofbirth = ele.get("Date_of_Birth");
age = dateofbirth.days360(zoho.currentdate);
mp = Map();
mp.put("Age",age);
update = zoho.crm.updateRecord("Contacts",contactid,mp);
}
info contactid;
info update;
}
Notes
- Replace "xxxxx" with the ID of the custom list view created in the above section. You can find this numeric ID in the URL of the custom view page.
- Make sure to use the accurate API names for their corresponding fields (e.g., "Date of Birth") in the code snippet. Learn more
- The function, when connected to a scheduler, can update up to 2,000 records at a time.
- The script above is an example of how to automatically calculate the age of your contacts on a daily basis by finding the difference between the current date and a specified date in a field. You can use this code for any other module, such as invoices, by modifying the module name and other parameters.
Test the solution
- Once the schedule has been executed, open the contact you wanted to update the age.
- Check whether the Age field was updated with the latest figure, and also check the Modified Time stamp to confirm the update via the schedule.
Tips
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
- When dealing with a custom list view with 5,000+ records, you can process them in a loop of three iterations, each handling 2000 records. For example, you can update up to 6,000 records, replacing the following values in the code snippet.
- list = {1,2,3,4,5,6,7,8,9,10};
- list = {11,12,13,14,15,16,17,18,19,20};
- list = {21,22,23,24,25,26,27,28,29,30};
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 PointSchedule
- EditionEnterprise and above
- ComplexityHigh
- Implementation Time60 minutes

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