Close all tasks associated with a deal, based on it's stage

Business scenario:

Winning a deal is never easy. There are a lot of stuff that you need to do in order to follow through with the deal. Qualification, Analysis, Value Proposition, Identifying Decision Makers, Proposals, Negotiations, etc are the stages of a deal. And there are a lot more mini-stages which are quite necessary. For instance, scheduling a call, reviewing a proposal, scheduling a product demo, etc. Those mini-stages are documented in your CRM as Tasks, which you or your boss can assign to yourself or others.

However, the thing is, the tasks are only relevant only before the deal is either won or lost. After the deal is done and dusted, there is no need for the existing tasks. It just takes up space and a bit of your time (you might do a periodic check). As a result, although you can manually close tasks, wouldn't it be convenient to close all the tasks when the deal stage is changed to "Closed (Won)", "Closed (Lost)" or "Closed (Lost to Competition)"?

This tip will help you create a workflow, which triggers the function to get executed whenever the deal stage is moved to Closed.


Getting started with the function:

  1. Go to Setup > Developer Space > Functions > + Create New Function.
  2. Select Automation as Function type and click Next.
  3. Provide a name for the function. Add a description(optional).
  4. Copy the code given below.
  5. Click Edit Arguments.
  6. Enter the name as dealId and select the type as Int.
  7. Click Save&Execute Script.
  8. Click Save.

The Code:

relatedTask = zoho.crm.getRelatedRecords("Tasks","Deals",dealId.toLong(),1,200);
//info relatedTask;
mapVariable = Map();
for each task in relatedTask
taskID = ifnull(task.get("id"),"");
status = ifnull(task.get("Status"),"");
if(status != "Completed")
updateTask = zoho.crm.update("Tasks",taskID.toLong(),mapVariable);
info updateTask;



  • Include this function in a Workflow Rule, with the conditions as executed whenever the field Stage is updated, Stage is Closed Won, Closed-Lost or Closed-Lost to Competition.
  • The above code works only for API V2.0 and not the previous version.

Found this useful? Try it out and let us know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful!

Return to Tips