Calculating customer lifetime value (LTV) is crucial for every business. It involves analyzing the customer's past deals that have been won and closed to determine the overall revenue generated over the course of their relationship with your business. This metric helps identify the most profitable customers over time and devise strategic plans to maintain their loyalty. Although this is a valuable business metric, accessing it within your CRM contact records will require customization.
Since this is a special requirement for most businesses, we support it through low-code tools. You just need to create a custom function and connect it to a workflow rule for the deals module to update a customer's lifetime value in their contact record.
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 Currency field in the Contacts module. This field will capture the sum value of all won and closed deals of a contact. Learn more
- Create a workflow rule for the Deals module that triggers every time a deal's stage is set to "Closed Won". Learn more
- Write a custom Deluge function and link it up 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 adding the custom currency field to the Contacts module.
- Navigate to Setup > Customization > Modules and Fields.
- Click the Contacts module to open the layout editor and do the following:
- Drag and drop the Currency field from the New Fields tray to the desired section of the layout.
- Name the currency field (e.g. "Contact LTV") and define its properties as required.
- Once you have finished, click Save.
Create a workflow rule
- Navigate to Setup > Workflow Rules > +Create Rule.
- Select Deals from the module dropdown list.
- Provide a name for the rule. For example: "Deals rollup to contact".
- Add a description (optional) and then click Next.
- In the Execute this workflow rule based on section, choose Record Action, then select Create or Edit from the dropdown and click Next.
- In the Which deals would you like to apply the rule to? section, specify the condition as "<Stage> is <Closed Won>" and click Next.
Note: Choose the appropriate stage that shows the deal is closed and invoiced. - Under Instant Actions, select Function and Write your own.
- Provide a name and description, if necessary, for the function.
- On the Deluge Script Editor, do the following:
- Copy and paste the code given below.
- Click Edit Arguments.
- Choose Contacts - Contact Id and name it as contactId, then click Save.
- Click Save & Execute Script.
- Click Save on the workflow rule page.
The code
relpot = zoho.crm.getRelatedRecords("Deals","Contacts",contactId.toLong());
total = 0.0;
if(relpot.size() > 0)
{
for each ele in relpot
{
total = total + ifnull(ele.get("Amount"),"0.0").toDecimal();
}
}
mp = Map();
//Enter the API name of the curreny field
mp.put("Contact_LTV",total);
update = zoho.crm.updateRecord("Contacts",contactId.toLong(),mp);
info mp;
info update;
Notes
- Make sure to use the accurate API names for their corresponding fields in the code snippet. Learn more
Tip
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Navigate to Deals > +Create Deal.
- On the Deal Details page, enter details such as deal name, account name, contact name, and amount.
- Change the deal's stage to "Closed Won" and click Save.
The workflow rule will be triggered. - Check whether the Contact LTV field in the related contact reflects the amount entered in the deal record. Create more deals for the contact to ensure the field shows the total sum of all amounts.
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