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

    • Make the edit fields hover in Canvas View look the same as the Detail Page

      The edit field UI in the Canvas View is not consistent with the standard detail page UI. For some modules we have Canvas views, for some we don't. We don't want it to look differently. We want it to look like one system.
    • Error when using fetchById in Client Script

      When using client script when creating page (onLoad), I suddenly getting error "Cannot read properties of undefined (reading 'Accounts')" when using: var account_details = ZDK.Apps.CRM.Accounts.fetchById(account_id); I'm getting this error whenever trying
    • Validating an order by a superior

      Hi, I have a very specific use case for Backstage. Let me know if this is possible or how I could get around this (or if there are no workaround). One of my client uses Backstage to manage internal (on site) events. Participants from different departments
    • iOS App Version 3.0 - Customer list gone?

      Not sure when this changed, but I seem to have been updated to 3.0 for the phone app (on iOS). I'm pretty sure that I used to have a Customers button that allowed me, for example, to see what appointments a customer has. Has this disappeared or am I just
    • Can't Find or Use Saved Replies in Inbox Module

      I'm an Admin user on Zoho Social, and I've created a few saved replies under Inbox Preferences > Saved Replies. However, when I go to the Inbox module to respond to a message, I don't see any option to insert or use saved replies. I've checked that: I'm
    • Episode II: Begin Your Automation Journey in Zoho Desk with Deluge

      To travel to another country, you need a passport. But that's not enough, you also need a visa, flight tickets, and, most importantly, a mode of transportation. Without these, your journey cannot begin. Similarly, custom functions in Zoho Desk are essential
    • How can I capture the Cliq channel name from Deluge Script?

      I am working on a chat automation with a third party tool called Make.com. Using a webhook I am relaying information from the Bot I have created in Zoho Cliq to Make.com Webhook. I am using the Mention Handler of the bot in Cliq to relay information like
    • Introducing Zoho CRM for Everyone: A reimagined UI, next-gen Ask Zia, timeline view, and more

      Hello Everyone, Your customers may not directly observe your processes or tools, but they can perceive the gaps, missed hand-offs, and frustration that negatively impact their experience. While it is possible to achieve a great customer experience by
    • Backstage Roadmap to Most Requested Features

      Please provide insight as to ETA for the following: 1. Backstage integration with Zoho Showtime, seems like a no-brainer.       1.a. Why does OnAir look eerily like Showtime integration we must 'pay extra for'? 2. Backstage Integration with Zoho Subscriptions
    • How to know number of days between Deal Stages?

      Hi Team - how do I know the number of days between Deal Stages? I have a Deal blueprint and I want to know the number of days it takes the Deal to be on Stage 3 to Stage 8? I can't seem to create a report for that. Our Deals have 11 Stages and our Purchasing department is in charge of Stage 3 to Stage 8 and I want to know the number of days it takes for them to complete their stages?
    • How To Change Open Activities View in Canvas?

      Hi all, I want to have my open activities have this view, but I cannot see how to make it look this way in Canvas. Not only that, but there isn't a way to rearrange the Standard view in Canvas, either. What I want (this is in the Standard layout): What
    • Queries in Custom Related Lists

      Hello everyone, We hope you’re having a great day! A while ago, we introduced Queries in Zoho CRM to help you dynamically fetch data from CRM modules or even external sources—right within your CRM interface. Many of you have already used Queries with
    • CRM HAS BEEN SOOO SLOW For Days 05/15/25

      I have fantastic Wifi speed and have zero issues with other websites, apps, or programs. It takes an excruciatingly amount of time to simply load a record, open an email, compose an email, draft a new template, etc. Am I in a subset/region of subscribers
    • Add a Calender view in Zoho CRM

      I would like to ask if it's possible to add a calendar view to a custom module in Zoho CRM. Is this feature planned for future development? It would be extremely helpful for us. I’d like to allow my users to view the data visually in a calendar layout,
    • Mass emails - Allow preview of which emails will receive the email based on the criteria

      Feature request. Please allow us to view and confirm the exact recipients of the mass emails based on the criteria we've chosen before sending. It can be quite sensitive if you send the mass email to some wrong accounts accidently, so it would be great
    • Customers not receiving emails

      So, a little backstory, we have been using Zoho Forms for the past eight years. And when we initially started, we would have email notifications be sent from inside Zoho Forms after a submission. We recently started using Zoho CRM as we wanted a better
    • Sum Total of various fields in child module and add value to parent module field

      Hi! Having trouble with a custom function, im trying to calculate the total of all the rent and sqm fields of our offices in Products module and have them transfer to the parent module Location. The API names are as below: Child module Products = "Products"
    • Automate your status with Cliq Schedulers

      Imagine enjoying your favorite homemade meal during a peaceful lunch break, when suddenly there's a PING! A notification pops up and ruins your moment of zen. Even worse, you might be in a vital product development sprint, only to be derailed by a "quick
    • Important! ZipRecruiter Sponsored Posting Plan Changes in Zoho Recruit

      Greetings, We’re reaching out to inform you about an important upcoming change to the ZipRecruiter Sponsored job board integration within Zoho Recruit. What’s Changing? Starting June 1, 2025, Zoho Recruit will be updated with ZipRecruiter's latest pricing
    • Generate Unique Customer ID for Each for All Contacts

      Generate Unique Customer ID for Each for All Contacts
    • Mails to Deals

      Hi everybody. We are using ZOHO CRM connected to ZOHO Mail and we have a big trouble, which our ZOHO partner is not able to solve. Zoho CRM automatically connects received emails to last edited live Deal of the same Contact. For us this logic is very
    •  【Zoho CRM】サブフォーム内にあとから追加した数式項目を一括して計算させる方法

      皆様のお知恵を拝借いたしたくご相談させてください。 【状況】 任意のタブにすでにサブフォームが設定されており、そのサブフォームを含め、既に数千件のデータが存在している。 【実施したいこと】 新たに数式項目をそのサブフォームに追加して、入力済データのレコードも含めて、その数式項目の計算結果を反映させたい。項目の更新で数式項目をサブフォームに追加しただけでは計算されません。 【わかっていること】 任意のタブのサブフォーム外にあとから数式項目を追加した場合、数式項目を追加しただけでは当然数式項目の計算結果は反映されませんが、以下の方法を実施すると数式項目が計算されます。
    • ICICI Bank integration

      Why the ICICI bank integration has been disabled? We opened the ICICI bank account only for integraton with Zoho. It is taking lot of time to do manual payments using file upload method. When will be the new ICICI bank integration enabled in India?
    • This domain is not allowed to add. Please contact support-as@zohocorp.com for further details

      I am trying to setup the free version of Zoho Mail. When I tried to add my domain, theselfreunion.com I got the error message that is the subject of this Topic. I've read your other community forum topics, and this is NOT a free domain. So what is the
    • Add Direct Ticket Link to Zoho Help Center Portal in Email Replies

      Hi Zoho Support Team, We hope you're doing well. We’d like to request a small but valuable improvement to enhance the usability of the Zoho Help Center portal (https://help.zoho.com/portal/en/myarea). Currently, when someone from Zoho replies to a support
    • Task reminder with custom function

      Hello! I am trying to create a custom function to add a task. With you guys helping, I could create a function but I could not set the reminder. Anyone knows how to add a reminder?  Thank you for your tips!
    • Google Drive

      How to add more modules in google drive as I don't want Zoho space? TIA
    • View Expenses in Zoho Books Without Approval or Reports in Zoho Expense

      Hello, I’m using both Zoho Books and Zoho Expense (on the free plan for both). I would like to view the expenses recorded in Zoho Expense within Zoho Books, but I read that they need to be approved first. Since I manage a small freelance business, I don’t
    • One notebook is on my Android phone app, but not on Web or PC app.

      This problem started in stages. At first my phone was occasionally failing to sync. Then I noticed two things added to my Phone App. One was an existing notebook had a new cover, and the other was a new Note Card with an odd text in it. These were only
    • Cant receive emails

      Hi, I just created an account and went through all steps. Everything has been set up from my end, but Ive sent a test mail to the newly created email address, but it never arrived. Can somebody please help me? Thanks!
    • Ajust quantities in another form based on subform, on form submission

      Hello, I have an Order form with a LineItems subform. The LineItems subform has many lookups that import data from various other forms. I want to deduct the quantity offered in one of those other form, called Offer. In another application I used the following
    • Workdrive connection in Zoho CRM not working

      Hi, in https://crm.zoho.com.au/crm/orgXXXXXX/settings/connections i have set up the connection for WorkDrive which is pretty much setting up the name and the scopes. But I get "WorkDrive API test response: {"errors":[{"id":"F7003","title":"Invalid OAuth
    • Best Way to Update Subscriber Preferences for an Existing List?

      We currently have a mailing list of over 43,000 contacts in Zoho Campaigns, and we’re looking to segment our list based on subscriber content preferences—things like Free Webinars, Local Training, Store Specials, and New Product Announcements. We’d like
    • Disappearing Mouse cursor in Zoho Mail / Windows 11 (Chrome + Edge)

      I'm seeing an issue when writing mails with the light theme with the mouse cursor being white and the document area also being white - making it nearly impossible to see the mouse cursor. I see the problem on Windows 11 under Chrome and Edge. (Yet to
    • Zoho CRM to Zoho Projects Workflow {"error":{"code":6831,"message":"Input Parameter Missing"}} connecting

      void automation.Untitled_Function(String ProjName) { resp = invokeurl [ url :"https://projectsapi.zoho.com/restapi/portals/" type :GET connection:"zohoprojects" ]; info "Portal API Response: " + resp; portalId = null; if(resp != null) { if (resp.containsKey("portals"))
    • What's New in Zoho Inventory | January - March 2025

      Hello users, We are back with exciting new enhancements in Zoho Inventory to make managing your inventory smoother than ever! Check out the latest features for the first quarter of 2025. Watch out for this space for even more updates. Email Insights for
    • Learning how to customize templates via code and best practices

      Hi! Our developers team want to learn how to edit our template files safely. The last time we messed with these files our site went down for a day and we had to reconfigure it from scratch. What are the best practices to do this? How can we get a template
    • Inquiry: Integrating In-house Chatbot with Zoho Desk for Live Agent Support

      Hi Team, We are exploring the possibility of integrating our existing in-house chatbot with Zoho Desk to provide seamless escalation to live agents. Our requirement is as follows: within our chatbot interface, we want to offer users a "Talk to Agent"
    • I need to know the IP address of ZOHO CRM.

      The link below is the IP address for Analytics, do you have CRM's? https://help.zoho.com/portal/ja/kb/analytics/users-guide/import-connect-to-database/cloud-database/articles/zoho-analytics%E3%81%AEip%E3%82%A2%E3%83%89%E3%83%AC%E3%82%B9 I would like to
    • You are forced to store/manage custom functions redundantly | Any solutions?

      Hello there, you are forced to store code (custom functions) redundantly if you want to use the same functionality in multiple departments. I don't understand that you can't define global functions. When I make a change to a function I may have to do
    • Next Page