Automation Series: Close all tasks once the project is completed

Automation Series: Close all tasks once the project is completed

When a project is marked as Completed, it might still have open tasks such as recurring tasks that were not marked as complete, tasks that are no longer relevant, or tasks that no longer need attention after closure.

To ensure the project reflects its final state, you can use a task workflow rule to automatically close all open tasks once the project reaches the Completed status.

To set this up,

First create a connection with Zoho Projects using these scopes:
  1. ZohoProjects.tasks.ALL
  2. ZohoProjects.projects.READ
  3. ZohoProjects.portals.READ
  4. ZohoProjects.milestones.ALL
Create a Custom Function and add the Deluge script below. Replace 'xxxxxxxxx' with your Zoho Projects connection name, and map the arguments listed below.

The below script removes task recurrences and closes all tasks in a project. In the below script, the connection name is "closealltasks"

  1. // TODO: Please create a connection for the Zoho Projects service with the scopes "ZohoProjects.tasks.ALL,  ZohoProjects.projects.READ,  ZohoProjects.portals.READ, ZohoProjects.milestones.ALL". Replace 'closealltasks' with the connection name. Click this link below to learn how to create the connection. 
  2. // Link - https://help.zoho.com/portal/en/kb/projects/integration/connections/articles/connections-23-5-2022#How_to_establish_a_Connection
  3. // TODO: Replace the status name (Closed status type) in Line No. 6, if needed.
  4. projectsAPIEndPoint = "https://projectsapi.zoho.com/restapi";
  5. projectsv3APIEndPoint = "https://projectsapi.zoho.com/api/v3";
  6. statusName = "Closed";
  7. statusId = null;
  8. /*  Close all tasks */
  9. //Fetch task layouts
  10. taskLayoutDetails = invokeurl
  11. [
  12. url :projectsAPIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/tasklayouts"
  13. type :GET
  14. connection:"closealltasks"
  15. ];
  16. // info taskLayoutDetails;
  17. if(taskLayoutDetails != null && taskLayoutDetails.get("status_details") != null)
  18. {
  19. statusDetails = taskLayoutDetails.get("status_details");
  20. for each  status in statusDetails
  21. {
  22. if(status.get("name").equalsIgnoreCase(statusName))
  23. {
  24. // Fetch task status id based on status name
  25. statusId = status.get("id");
  26. info status.get("name") + " : " + statusId;
  27. break;
  28. }
  29. }
  30. }
  31. if(statusId != null)
  32. {
  33. indexValue = 1;
  34. rangeValue = 100;
  35. loop = {1,2,3,4,5,6,7,8,9,10};
  36. predStatusMap = Map();
  37. // This loop fetches up to 300 tasks. Increase the count as needed, e.g., loop = {1,2,3,4,5}; to fetch 500 tasks.
  38. for each  i in loop
  39. {
  40. taskParameter = Map();
  41. taskParameter.put("index",indexValue);
  42. taskParameter.put("range",rangeValue);
  43. taskParameter.put("status","notcompleted");
  44. //  info taskParameter;
  45. taskResponse = zoho.projects.getRecords(portalId,projectId,"tasks",taskParameter,0,"closealltasks");
  46. //  info taskResponse;
  47. if(taskResponse.containKey("tasks"))
  48. {
  49. taskIds = list();
  50. for each  task in taskResponse.get("tasks")
  51. {
  52. taskId = task.get("id");
  53. if(task.get("is_recurrence_set"))
  54. {
  55. updateTaskParameter = Map();
  56. updateTaskParameter.put("json_string",{"recurrence":{"recurring_frequency":"none","time_span":"1","number_of_occurrences":"2","is_comments_recurred":false,"recurrence_type":"after_current_task_completed"}});
  57. updateTaskResponse = zoho.projects.update(portalId,projectId,"tasks",taskId,updateTaskParameter,"closealltasks");
  58. info updateTaskResponse;
  59. }
  60. if(task.containsKey("dependency") && task.get("dependency").containsKey("predecessor"))
  61. {
  62. predTasks = task.get("dependency").get("predecessor");
  63. predList = list();
  64. for each  predTaskId in predTasks
  65. {
  66. predList.add(task.get("dependency").get("dependencyDetails").get(predTaskId).get("IS_COMPLETED"));
  67. }
  68. if(!predList.contains(false))
  69. {
  70. taskIds.add(taskId);
  71. }
  72. }
  73. else
  74. {
  75. taskIds.add(taskId);
  76. }
  77. info "taskIds : " + taskIds;
  78. }
  79. bulkUpdateParams = Map();
  80. bulkUpdateParams.put("taskids",taskIds.toText().remove("[").remove("]"));
  81. bulkUpdateParams.put("status",{"id":statusId});
  82. info bulkUpdateParams;
  83. /* Bulk update */
  84. taskBulkUpdate = invokeurl
  85. [
  86. url :projectsv3APIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/tasks/bulk-update"
  87. type :PATCH
  88. parameters:bulkUpdateParams.toString()
  89. connection:"closealltasks"
  90. ];
  91. info taskBulkUpdate;
  92. }
  93. else
  94. {
  95. break;
  96. }
  97. }
  98. }
  99. return "success";

Argument Mapping:
  1. portalId - Portal System ID
  2. projectId - Project System ID

After saving the custom function, create a workflow rule with the following settings:



Once the rule is saved, all open tasks are completed automatically whenever a project is marked as Completed. This ensures the project reflects its true closure state, avoids manual cleanup and keeps your project up to date.

If you have any questions, please drop comments below or email us at support@zohoprojects.com.



      Zoho Campaigns Resources


        • Desk Community Learning Series


        • Digest


        • Functions


        • Meetups


        • Kbase


        • Resources


        • Glossary


        • Desk Marketplace


        • MVP Corner


        • Word of the Day


        • Ask the Experts


          • Sticky Posts

          • Time Log Reminder

            Tracking the time spent on tasks and issues is one of the most important functions of a timesheet. However, users may forget to update the time logs because they have their own goals to achieve. But, time logs must be updated at regular intervals to keep
          • Introducing the Zoho Projects Learning Space

            Every product has its learning curve, and sometimes having a guided path makes the learning experience smoother. With that goal, we introduce a dedicated learning space for Zoho Projects, a platform where you can explore lessons, learn at your own pace,
          • Update on V2 API End-of-Life Timeline

            Dear Users, Earlier this year, we shared the launch of the V3 APIs and requested users to migrate from the older V2 APIs by December 2025. We have received valuable feedback from our users and partners regarding their migration timelines. We are happy
          • Automation Series: Auto-update Phase Status

            Hello Folks! You can auto-update your phase's status based on status of underlying tasks using custom functions. In this series, we will showcase how to create and run custom functions, using Deluge, with ease. Follow the steps below and automate your
          • Automate Timesheet Approvals with Multi-level Approval Rules

            Introducing Approval Rules for Timesheets in Zoho Projects. With this automation, teams can manage how timesheets are reviewed and approved by setting up rules with criteria and assigning approvers to handle submissions. Timesheet, when associated to

          Zoho CRM Plus Resources

            Zoho Books Resources


              Zoho Subscriptions Resources

                Zoho Projects Resources


                  Zoho Sprints Resources


                    Zoho Orchestly Resources


                      Zoho Creator Resources


                        Zoho WorkDrive Resources



                          Zoho CRM Resources

                          • CRM Community Learning Series

                            CRM Community Learning Series


                          • Tips

                            Tips

                          • Functions

                            Functions

                          • Meetups

                            Meetups

                          • Kbase

                            Kbase

                          • Resources

                            Resources

                          • Digest

                            Digest

                          • CRM Marketplace

                            CRM Marketplace

                          • MVP Corner

                            MVP Corner




                            Zoho Writer Writer

                            Get Started. Write Away!

                            Writer is a powerful online word processor, designed for collaborative work.

                              Zoho CRM コンテンツ



                                ご検討中の方