Close all tasks associated with a lead and create a new 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 function:

  1. Go to Setup > Customization > Modules and Fields > Select the required module > Links and Buttons > + New Button.
  2. Provide a name for the button. Add a description(optional).
  3. Choose View Page from the drop-down list.
  4. Select Writing Function from the subsequent drop-down.
  5. Provide a name for the function. Add a description(optional).
  6. Copy the code given below.
  7. Click Edit Arguments.
  8. Enter the name as recid and select the value as Lead Id.
  9. Enter the name as leadowner and select the value as Lead owner Id.
  10. Save the changes.
  11. Select the profiles who can see this button.
  12. Click Save.
 

The Code:


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";
 

Note:

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