Update the latest deal closing date

Record the closing date of the most recent deal of an account in its custom field to allow for quick insights into the account's activity and future business opportunities.

Tracking your customer accounts' last deal closing date is important for your sales and marketing strategies. For example, salespeople can identify accounts that haven't made recent purchases to explore opportunities for up-selling or cross-selling. Similarly, the marketing team can target accounts that require re-engagement by sending follow-up messages, discount offers, or launching campaigns to reconnect with them. However, manually updating this date in account records by reviewing all the related deals can be time consuming. What if you could do this automatically whenever a new deal is closed as won in your CRM? Our low-code tools can come in handy in this scenario.

Using a combination of a custom field, deluge script, and a workflow rule, you can automatically update an account with its last deal closing date. The Deluge script runs through all the closed-won deals created for an account and updates the closing date of the most recent deal in a custom field. Read on 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 Date field in the Accounts module. This field will capture the closing date of the most recent deal created for an account. Learn more
  • Create a workflow rule for the Deals module that triggers upon marking a deal as 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 a custom date field to the Accounts module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Accounts module to open the layout editor.
  3. Drag and drop the Date field from the New Fields tray to the desired section of the layout.
  4. Name the date field (e.g., "Last Deal Won Date") and define its properties as required.
  5. Once you have finished, click Save and Close.

Create a workflow rule

The next step is creating a workflow rule in your CRM account.

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select Deals from the module dropdown list.
  3. Provide a name for the rule. For example: "Update deal closing date in accounts".
  4. Add a description (optional) and then click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Record Action, then select Create or Edit from the dropdown.
    2. Check the Repeat this workflow whenever a deal is edited option.
    3. Click Next.
  6. In the Which deals would you like to apply the rule to? section, select All Deals, then click Done.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a Name for the function, as well as a description, if necessary.
  9. In the Deluge Script Editor, do the following:
    1. Copy and paste the code given below.
    2. Click Edit Arguments.
    3. Enter the name as accountID, select the value as Accounts - Account Id, then click Save.
    4. Click Save & Execute script.
  10. Click Save on the workflow rule page.

The code

Code Copied
relatedDeals = zoho.crm.getRelatedRecords("Deals","Accounts",accountID);
dateList = List();
if(relatedDeals != null)
{
	for each  deal in relatedDeals
	{
		if(deal.get("Stage") == "Closed Won")
		{
			closingDate = deal.get("Closing_Date").toDate();
			dateList.add(closingDate);
		}
	}
	dateList = dateList.sort(false);
	info "dateList :  " + dateList;
	update = zoho.crm.updateRecord("Accounts",accountID,{"Last_Deal_Won_Date":dateList.get(0)});
	info "update : " + update;
}

Notes

  • Make sure to use the accurate API name of the custom date field (e.g., "Last Deal Won Date") in the code snippet. Learn more
  • The code above is an example of how to update the closing date of the most recent deal of an account in its custom field. You can use this code to update the average purchase cycle in other modules, such as Contacts, by modifying the module name and parameters.

Tip

  • Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.

Test the solution

  1. Navigate to the Accounts module.
  2. Open an account record, click Deals under the Related List, and click the + icon to add a new deal.
    Note: You can also edit and update an existing deal as closed-won.
  3. Enter the required deal information, set its stage to Closed Won, and click Save.
    The workflow rule will be triggered.
  4. Check whether the corresponding account's Last Deal Won Date field reflects the deal's closing date.
  5. Create two or more closed won deals with varied dates to verify whether the most recent one gets updates in the account.

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

  • ModuleAccounts
  • Trigger PointWorkflow Rule
  • EditionEnterprise and above
  • ComplexityMedium
  • Implementation Time30 minutes

Features used in the solution

Custom FieldWorkflow RuleDeluge ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!