Function #34: Close all tasks associated with a deal based on it's stage.

Function #34: Close all tasks associated with a deal based on it's stage.



Welcome back everyone!

Last week, we learnt how to create Accounts from Leads with all the data at the click of a button. This week, let's look at a custom function that lets you close all of the tasks associated with a deal depending upon the deal 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 week's tip helps you create a workflow, which triggers the function to get executed whenever the deal stage is moved to Closed.

Getting started with the custom function:

  • Go to Setup > Automation > Actions > Functions > Configure Function > Write your own.
  • Provide a name for the function. For example: "Close all tasks". Add a description(optional).
  • Copy the code given below.
  • Click “Edit arguments”.
  • Enter the name as “dealId” and select the value as “Deal Id”.
  • Click Save&Execute Script to check the code.
  • Save the function.

The Code:

For V2 API - DRE Editor:

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")
{
mapVariable.put("Status","Completed");
updateTask = zoho.crm.update("Tasks",taskID.toLong(),mapVariable);
info updateTask;
}
}


For V1 API - Old Editor :

relatedTask = zoho.crm.getRelatedRecords("Tasks","Potentials",dealId.toString(),1,200);
//info relatedTask;
mapVariable = Map();
for each task in relatedTask
{
taskID = ifnull(task.get("ACTIVITYID"),"");
status = ifnull(task.get("Status"),"");
if(status != "Completed")
{
mapVariable.put("Status","Completed");
updateTask = zoho.crm.update("Tasks",taskID.toString(),mapVariable);
info updateTask;
}
}


Note:

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 code is zoho.crm._getRelatedRecords for Version 1.0 of APIs.


Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful. Do check out other custom functions shared in this series here.

See you all next week with another interesting custom function. Ciao!

    • Sticky Posts

    • How to reach the official Zoho Support channels and avoid fake ones.

      Dear Customers, Thanks a lot for choosing Zoho! Our applications are built to help achieve your day-to-day business goals. We are committed to engaging with you, to understand and develop solutions that enhance your productivity.  We are happy and ready to help you use our services effectively. Understanding and avoiding fake support Just like using popular bank names and financial applications for phishing purposes, using Zoho and claiming to be providing Zoho Support or services with false numbers
    • Function #35: Close all tasks associated with a lead and create a new task.

      Welcome back everyone! Last week, we learnt how to close all tasks of a deal depending upon the deal stage. This week, let's look at a custom function that lets you close all of the tasks associated with a lead while simultaneously creating a new task, like when you need to halt all progress towards a lead while the lead is not available at the moment but create a reminder task. Business scenario: The success of a company, in one way or another, is determined by the leads it gets. Each lead is just
    • Zoho CRM Webinar - Redesigning Daily User Experiences with Canvas

      <br> Your users across roles use the CRM for day-to-day tasks that are necessary. Whether they perform their tasks on time, the right way, or at all depends on a lot of factors, including User Experience. Many businesses struggle with rigid layouts,
    • Join us at the Canada ZUG Meetup: What’s New in Zoho CRM

      Hello Zoho Community! Start your year with fresh insights into Zoho CRM’s latest updates and tools. Whether you're a CRM beginner or a experienced user, this meetup is crafted to help you optimise your processes and leverage new features. Explore practical
    • CRM Hack #2: Automate sending of birthday greetings to your customers.

        Hello everyone! What sets you apart as a sales person is your ability to add that personal touch to your business relationship with your customers. Sending a gift on a special day, or leaving a note wishing them on their birthdays, are small, yet significant actions that show your customers that you care. And these are actions done without any expectations :) You must be engaging with a lot of customers and it is highly unlikely that they all are your friends on Facebook or some social channel,