Function #35: Close all tasks associated with a lead and create a new task.

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 as important and turning a lead into a deal takes a lot of skill and time. The help we (CRM) provide can reduce your workload a bit. As you grow, the tasks that everyone in the company needs to do grow too.

Today, let's look at a scenario where you would need to close all the ongoing tasks for a lead and create a completely new one. For instance, let's say you created tasks for call follow-up, product demo, in-person meet and negotiation. If the lead decides to postpone the arrangements due to an emergency, it is not required to have all the tasks as is, since there might be periodic check on the completed and ongoing tasks.

In that case, add a button in the leads module with this function to close all the existing tasks and create a new one with the task as "Open all tasks again when lead is available.". Convenient, right?

Getting started with the custom function:
  1. Go to Setup > Customization > Modules > Deals > Links and buttons > Create new button.
  2. Provide a name for the button. For example: "Close all tasks & create new". Add a description(optional).
  3. Select the placement of the button as View page.
  4. Select the action to be performed as "Writing function".
  5. Copy the code given below.
  6. Click “Edit arguments”.
  7. Enter the name as “recid” and select the value as “Lead Id”.
  8. Enter the name as “leadowner” and select the value as “Lead owner id”.
  9. Click Save&Execute Script to check the code.
  10. Save the script.
  11. Select the profiles who can view this button.
  12. Click Save.
The Code:

For V2 API - DRE Editor:
------------------------------------------------------------------------------------------
reltasks = zoho.crm.getRelatedRecords("Tasks", "Leads", recid.toLong(),1,200);
for each rec in reltasks
{
reltaskid = rec.get("id");
update = zoho.crm.update("Tasks", reltaskid, {"Status":"Completed"});
}
mp = map();
mp.put("Subject","Test");
mp.put("Due_Date",today.toString("yyyy-MM-dd"));
mp.put("Status","Not Started");
mp.put("$se_module","Leads");
mp.put("What_Id",recid);
mp.put("Owner",leadowner);
create = zoho.crm.create("Tasks", mp);
info create;
return "Success";
------------------------------------------------------------------------------------------

For V1 API - Old Editor :
------------------------------------------------------------------------------------------
recidStr = input.recid.toString();
reltasks = zoho.crm._getRelatedRecords("Tasks", "Leads", recidStr,1,200);
for each rec in reltasks
{
reltaskid = rec.get("ACTIVITYID");
update = zoho.crm._updateRecord("Tasks", reltaskid, {"Status":"Completed"});
}
mp = map();
mp.put("Subject","Test");
mp.put("Due Date",today.toString("yyyy-MM-dd"));
mp.put("Status","Not Started");
mp.put("SEMODULE","Leads");
mp.put("SEID",recid);
mp.put("SMOWNERID",leadowner);
create = zoho.crm._create("Tasks", mp);
info create;
return "Success";
------------------------------------------------------------------------------------------

Note:

  • Include this function in a Button, within the Leads module and set it in the View page.
  • 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

    • (Cancelled) UK In-person Zoho User Group (ZUG) Meetups - Learn, share and discuss all things Zoho

      Hi there, Hope you all are well. We're thrilled to announce the next series of in-person Zoho User Group (ZUG) meetups in the UK. Following the success of our first leg of meetups in 2024, where Zoho experts had the opportunity of engaging with users.
    • 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
    • ZUG (Zoho User Group) In-person Meetups - Learn, Share, and Discuss All Things Zoho

      Hi, We hope you are all doing well. We are excited to announce the second leg of our in-person Zoho User Group (ZUG) meetups in your region. A quick update: Our first leg of meetups in 2024 reached completion, and Zoho experts had the opportunity to meet
    • Tip #35 - On using Kanban View in Zoho CRM

      Hi folks,  It's that time of the week again, and I am back with a quick tip about using Kanban View in Zoho CRM. If you think you missed any of our previous weeks' tips, you can read them here.  Tip #35 - On using Kanban View in Zoho CRM You deal with so many records in CRM every single day! When you click open each module in Zoho CRM, you have hundreds of records, each in various stages of your sales pipeline. Wouldn't it be cool if you had them all sorted automatically without having to filter
    • ZUG (Zoho User Group) In-person Meetups - Learn, share and discuss all things Zoho

      Hi, Hope you all are well. We're excited to announce our second leg of in-person Zoho User Group (ZUG) meetups in your region. A quick update - Our first leg of meetups in 2024 progressed and reached completion smoothly, where Zoho experts had the opportunity