To effectively manage deals that progress through multiple stages, scheduling various activities for your salespeople to engage with potential customers, such as calls and meetings, is common. However, not all deals reach a successful conclusion. When a deal is marked as lost, the open activities associated with it become obsolete and some of the customers would like to delete them from their CRM system.
This scenario is a special requirement and not typical for all customers, so we support it through low-code tools. This custom function helps you delete all open activities, such as calls, tasks, and events associated with a deal, when triggered through a workflow rule upon marking a deal as closed lost.
Permissions and availability
- 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
- Create a workflow rule for the Deals module to auto-delete open activities when their stage is set to "Lost". 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 in your production environment. Learn more
Create a workflow rule
Follow the steps below to create a workflow rule in your Zoho CRM account:
- Navigate to Setup > Workflow Rules > +Create Rule.
- Select the Module as Deals from the drop-down list.
- Provide a name for the rule. For example: "Auto-delete open activities".
- Add a description, if required, then click Next.
- In the Execute this workflow rule based on section, do the following:
- Choose Record Action, then select Edit from the drop-down.
- Check the box for Repeat this workflow whenever a Deal is edited.
- Choose Specific field(s) gets modified from the drop-down, then enter the condition "When <Stage> is modified to <any LOST stages>".
- Click Next.
- In the Which deals would you like to apply the rule to? section, select All Deals and click Next.
- Under Instant Actions, select Function and Write your own.
- Provide a Name and description, if required, for the function.
- On the Deluge Script Editor, do the following:
- Copy and paste the code given below.
- Click Edit Arguments.
- Choose Deal Id, name it as dealId, then click Save.
- Click Save & Execute Script.
- Click Save on the workflow rule page.
The code
relclosedact = zoho.crm.getRelatedRecords("Activities","Deals",dealId.toLong(),1);
info "relclosedact : " + relclosedact;
if(relclosedact.size() > 0)
{
for each act1 in relclosedact
{
if(act1.get("Activity_Type") == "Tasks")
{
deleteResp = zoho.crm.invokeConnector("crm.delete",{"module":"Tasks","id":act1.get("id")});
info "task deleted : " + deleteResp;
}
if(act1.get("Activity_Type") == "Events")
{
deleteResp = zoho.crm.invokeConnector("crm.delete",{"module":"Events","id":act1.get("id")});
info "event deleted : " + deleteResp;
}
if(act1.get("Activity_Type") == "Calls")
{
deleteResp = zoho.crm.invokeConnector("crm.delete",{"module":"Calls","id":act1.get("id")});
info "calls deleted : " + deleteResp;
}
}
}
Notes
- Make sure to use the accurate API names for their corresponding fields in the code snippet. Learn more
- The code above is an example of deleting all associated open activities, such as calls, tasks, and events, upon marking a deal as closed lost. You can use this code for any other module, such as leads, by modifying the module name, status, 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
- Click the Deals tab.
- Open a deal record with open activities such as tasks, calls, and events.
- Update the deal's stage to 'Closed Lost'.
The workflow rule will be triggered. - See whether all the open activities linked to the deal are deleted.
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
- ModuleDeals
- 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