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

    • 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,
      • Recent Topics

      • Exciting Updates to the Kiosk Studio Feature in Zoho CRM!

        Hello Everyone, We are here again with a series of new enhancements to Kiosk Studio, designed to elevate your experience and bring even greater efficiency to your business processes. These updates build upon our ongoing commitment to making Kiosk a powerful
      • Reply to Email for SO/PO

        Hello, We are new to Zoho Books and running into an issue. Our support@ email is our integration user. When our team is sending out PO/SO's we are updating the sender email, but for some reason many of our responses are coming back to our support@ email
      • Ticket Loop from Auto Responce

        We’re seeing an issue where a client’s help desk triggers a ticket loop. When they email us, our system creates a ticket and sends the acknowledgement. Their system then creates a ticket from that acknowledgement and sends one back to us, which creates
      • How to make rule to filter out some emails from receiving the notification "Receiving a new ticket"?

        Good Morning, We are currently using the "Receiving a new ticket" notification rule to provide that auto reply template to a customer that emails us for support. However, there are some emails we don't want to receive this auto-reply. Where can I set
      • Zoho Signatures Missing

        In the past after collecting signatures from two different PDFs I would merge them by calling an api and the signatures would appear in the combined PDF. Recently the signatures have disappeared whenever I combine the PDFs together. Why did this randomly
      • New activity options for workflows

        Greetings, We are excited to announce the addition of two new dynamic actions to our workflow functionality: Create Event and Schedule Call. These actions have been thoughtfully designed to enhance your workflow processes and bring more efficiency to
      • Remove the “One Migration Per User” Limitation in Zoho WorkDrive

        Hi Zoho WorkDrive Team, Hope you are doing well. We would like to raise a critical feature request regarding the Google Drive → Zoho WorkDrive migration process. Current Limitation: Zoho WorkDrive currently enforces a hard limitation: A Zoho WorkDrive
      • Enrich your contact and company details automatically using the Data Enrichment topping

        Greetings, I hope you're all doing well. We're happy to announce the latest topping we've added to Bigin: The Data Enrichment topping, powered by WebAmigo. This topping helps you automatically enhance your contact and company records in Bigin. By leveraging
      • Important Update: Google Ads & YouTube Ads API Migration

        To maintain platform performance and align with Google's newest requirements, we are updating the Google Ads and YouTube Ads integrations by migrating from API v19 to the newer v22, before the official deprecation of v19 on February 11, 2026. Reference:
      • Enhancements for Currencies in Zoho CRM: Automatic exchange rate updates, options to update record exchange rates, and more

        The multi-currency feature helps you track currencies region-wise. This can apply to Sales, CTC, or any other currency-related data. You can record amounts in a customer’s local currency, while the CRM automatically converts them to your home currency
      • validation rules doesn't work in Blueprint when it is validated using function?

        I have tried to create a validation rule in the deal module. it works if I try to create a deal manually or if I try to update the empty field inside a deal. but when I try to update the field via the blueprint mandatory field, it seems the validation
      • Kaizen #228 - Process Large-Scale Migrated Data Using Catalyst Solutions

        Howdy, tech wizards! This week’s Kaizen explores how Catalyst Solutions in the Zoho CRM Developer Hub help import large volumes of data into Zoho CRM while improving data quality and simplifying the migration process. Why Catalyst Solutions? Catalyst
      • Getting Subform Fields to Display Top to Bottom

        I have a form where the fields are all in one column. I want to insert a subform where the fields are stacked in one column as well. I have built both the form and subform but the subform displays the fields from left to right instead of a stacked column. This will cause a problem displaying the subform correctly on mobile apps. How can I do this please?' Here is my form with subform now. As you can see the subform "Follow Up Activity" is displaying the fields left to right. I need them to go top
      • Zoho Expense Import Reports Won't Work Because Default Accounts Already Exist

        Im trying to import reports from another Zoho expense account to mine and im getting errors that won't allow the import to happen The account name that you've entered 'Ground Transportation' already exists. Enter another name for the account and try again.z
      • Inactive License for free account.

        I recently upgraded my Cliq subscription not my team (on the free version), are unable to login to their accounts. The error message received is Inactive License Looks like you have not been covered under the current free plan of users. Please contact
      • 2026 Product Roadmap and Upcoming Features

        This is your guide to what is coming in Zoho Vertical Studio throughout 2026. We’ll update this post throughout the year as items move from development to release, and as and when new initiatives are added. Once a feature is released, it will be reflected
      • Syncing zoho books into zoho crm

        I was wondering how I can use zoho books in crm as I have been using them separately and would like to sync the two. Is this possible and if so, how? Thanks
      • Release Notes | January 2026

        We have rolled out a set of powerful new enhancements across Zoho Vertical Studio that bring several long-awaited capabilities to your applications. These updates focus on deeper customization, smarter automation, better reporting, and improved usability
      • Live Chat for user

        Hi everyone, I’m new to Zoho Creator and wanted to ask if it’s possible to add a live chat option for all logged-in portal users so they can chat internally. I’m trying to create a customer portal similar to a service desk, but for vehicle breakdowns,
      • Power up your Kiosk Studio with Real-Time Data Capture, Client Scripts & More!

        Hello Everyone, We’re thrilled to announce a powerful set of enhancements to Kiosk Studio in Zoho CRM. These new updates give you more flexibility, faster record handling, and real-time data capture, making your Kiosk flows smarter and more efficient
      • Announcing new features in Trident for Mac (1.34.0)

        Hello everyone! We’re excited to introduce the latest updates to Trident, which are designed to take workplace communication to the next level. Let’s take a quick look at what’s new. Connect with customers using Zoho Voice integration. You can now easily
      • Massive Zoho Books failure

        We have not received any communication or notification from Zoho, but we have detected that Zoho Books is not working for all our users. We cannot access or use Zoho Books. This is critical. We are trying to contact Zoho on the Spain telephone number,
      • The Social Wall: January 2026

        Hello everyone, We’re back with the first edition of The Social Wall of 2026. There’s a lot planned for the year ahead, and we’re starting with a few useful features and improvements released in January to help you get started. Create a GBP in Social
      • How to block whole domain?

        I am getting at least 50-75sometimes over 100 spams emails a day. I see a lot of the spam is coming from .eu domains. I would like to block /reject all email coming for the .eu domain. I do not have any need for email from .EU domains. Why won't the BlackList
      • How Zoho Contracts Makes Negotiations Clear, Secure, and Transparent

        Negotiation is one of the most critical—and often most chaotic—stages of the contract lifecycle. Multiple stakeholders review the same document, propose changes, debate terms, and exchange feedback. Without the right tools, this collaborative process
      • Error: Invalid Element tax_override_preference

        In both Books and Inventory, we're getting the following error whenever we try to enter any Bill: I think this is a bug. Even cloning an old bill (that obviously was entered just fine), this error occurs.
      • Assign Income to Project Without Invoice

        Hello, Fairly new user here so apologies if there is a really obvious solution here that I am just missing... I have hundreds of small deposits into a bank account that I want to assign to a project but do not want to have to create an invoice every time
      • How to Print the Data Model Zoho CRM

        I have created the data model in Zoho CRM and I want the ability to Print this. How do we do this please? I want the diagram exported to a PDF. There doesnt appear to be an option to do this. Thanks Andrew
      • Please, make writer into a content creation tool

        I'm tired of relying on Google Docs. I'm actually considering moving to ClickUp, but if Writer were a good content creation tool instead of just a word processor, I would finally be able to move all my development within the Zoho ecosystem, rather than
      • our customers have difficult to understand the Statements

        our costumers have big problems to understand Zohos Statements. we need a text box after the payment number to explain what the payments are for. Is it possible to develop a version of the Statement with that kind of box and if so whu can do it
      • How to track a list of ALL the items that ONE customer bought?

        Hello, I am interested in getting a list of all the items that only ONE of my customers bought, and the invoices are what show up instead. It's very tedious to go through every single invoice when we sell a lot of items to this customer. Surely there
      • Exchange Rate Updates

        Hi, It would be great that when you work with multiple currencies, the exchange rate updates automagically every day (as seen on Zoho Books) or at least that when you create/update an opportunity the exchange rate could be manually updated, or maybe both!
      • Locked Out of Super Admin Account

        I'm locked out of my Super Admin account and the external e-mail is no longer associated with it. There seems to be a problem during set up, the system ought to ask to assign a new password instead of using Google accounts. Please help me get back access.
      • Emails are going to notification folder and not in inbox

        emails are going to notification folder and not into inbox
      • 550 5.4.6 Unusual sending activity detected. Please try after sometime

        Hi, I am receiving this error message when trying to send my emails. The only reason I can think why this is happening is my previous two emails were bounced back to me due to a non working mailbox error. I have followed the online links for unblocking
      • Projects Home Customization

        Hello! We've been in Zoho One since July of last year, and my team has started providing feedback on what they'd like to do. Their latest wish is that they could have more control over the Projects Home content. For example, they want a card that shows
      • IMAP search support

        Does Zoho Mail support IMAP search? https://www.rfc-editor.org/rfc/rfc9051.html#name-search-command TEXT <string> Messages that contain the specified string in the header (including MIME header fields) or body of the message. Servers are allowed to implement
      • Performance is degrading

        We have used Mail and Cliq for about three years now. I used to use both on the browser. Both have, over the past 6 months, had a severe degradation in performance. I switched to desktop email, which appeared to improve things somewhat, although initial
      • Cannot reorder fields in Page Layout in Expenses and Purchase Requests

        It is very inconvenient that the custom fields in Page Layout cannot be re-ordered. The only way is to remove the fields and re-create them; however, it is impractical. This would affect the reports and dashboards we are having. Not able to re-order the
      • bouncing emails

        My recurring invoices have bounced back
      • Next Page