Automation Series: Auto-update Task Closure Field Based on Due Date

Automation Series: Auto-update Task Closure Field Based on Due Date

In a project, tasks are owned and worked on by different users and each progresses at a different rate. With Zoho Projects, the task delay duration can be calculated automatically when a task runs past its due date. This gives project managers better visibility into delivery estimates without checking each task individually.

Consider an onboarding team working on tasks such as Contractor Enrolment, Implementation Timeline Discussion, and Lead Assignment, each aligned to a go-live schedule. As work moves forward, tasks are picked up and worked on by different members along the way. It gets tedious to calculate task delays individually as the project expands, making delivery reviews repetitive and time consuming.

 Whenever a task is marked as Completed, the workflow rule is triggered and the associated custom function compares the task Completion date against its Due date. Tasks that closed on or before the Due date are updated as On Time in the Closure field. Tasks that closed after the Due date are updated as Delayed and the number of overdue days is calculated and updated automatically. This helps project managers determine tasks that consistently take longer than planned, so future timelines can be adjusted before delays happen.

To configure this flow in your Zoho Projects portal,

      1. Navigate to the upper-right corner of the page and click   → Customization → Layouts and Fields → Tasks.
      2. Click the required layout and drag and drop to create the following Custom status and fields:
    1. Closure - Custom Picklist field with two values: On Time and Delayed.
    2. Days - Number field to capture the number of days delayed. This field will only populate when the closure status is Delayed.
    3. Stop - Checkbox field to prevent the Workflow Rule from repeatedly triggering after the task is updated.
    4. Re Open and Completed - Ensure the following statuses are available in your Task Layout. 


      3. Click Save.
      4. Navigate to   → Developer Space → Connections.
      5. Click Create Connection, choose Zoho Projects as the service, and add the following scopes:
    1. ZohoProjects.tasks.UPDATE
    2. ZohoProjects.portals.READ
    3. ZohoProjects.projects.READ


      6. Navigate to Custom Functions under Developer Space.
      7. Click the Tasks tab in the upper navigation panel.
      8. Create a new custom function and add the following Deluge script.
Notes
Ensure that the portal URL aligns with your data centre. If not, the function may not execute as expected.
  1. // scopes: ZohoProjects.tasks.UPDATE, ZohoProjects.portals.READ, ZohoProjects.projects.READ
  2. projectsV3Endpoint = "https://projectsapi.zoho.in/api/v3/portal/";
  3. endPoint = "https://projects.zoho.in/restapi/portal/";
  4. format = "dd-MM-yyyy";
  5. statusName = "Completed";
  6. // Get task layout details
  7. taskLayoutDetailsResponse = invokeurl
  8. [
  9. url :endPoint + portalId + "/projects/" + projectId + "/tasklayouts"
  10. type :GET
  11. connection:"fieldupdateoncompletion"
  12. ];
  13. statusDetails = taskLayoutDetailsResponse.get("status_details");
  14. for each status in statusDetails
  15. {
  16. if(status.get("name").equalsIgnoreCase(statusName))
  17. {
  18. completedStatusId = status.get("id");
  19. }
  20. }
  21. params = Map();
  22. if(endDate != null)
  23. {
  24. days = daysBetween(toDate(zoho.currentdate.toString(format),format),toDate(toString(endDate,format)));
  25. if(days >= 0)
  26. {
  27. params.put("closure","On time");
  28. params.put("stop",true);
  29. updateTask = invokeurl
  30. [
  31. url :projectsV3Endpoint + portalId + "/projects/" + projectId + "/tasks/" + taskId
  32. type :PATCH
  33. parameters:params.toString()
  34. connection:"fieldupdateoncompletion"
  35. ];
  36. }
  37. if(days < 0)
  38. {
  39. delayedDays = days * -1;
  40. params.put("closure","Delayed");
  41. params.put("days",delayedDays);
  42. params.put("stop",true);
  43. updateTask = invokeurl
  44. [
  45. url :projectsV3Endpoint + portalId + "/projects/" + projectId + "/tasks/" + taskId
  46. type :PATCH
  47. parameters:params.toString()
  48. connection:"fieldupdateoncompletion"
  49. ];
  50. }
  51. }
  52. params.clear();
  53. params.put("status",{"id":completedStatusId});
  54. updateTask = invokeurl
  55. [
  56. url :projectsV3Endpoint + portalId + "/projects/" + projectId + "/tasks/" + taskId
  57. type :PATCH
  58. parameters:params.toString()
  59. connection:"fieldupdateoncompletion"
  60. ];
  61. return "success";
Info
  1. Lines 2 and 3: Replace the domain in the endpoint URLs to match your data centre.
  2. Line 5: Replace "Completed" with the custom task closure status configured in your portal.
  3. Lines 11, 34, 48 and 59: Replace "fieldupdateoncompletion" with your Zoho Projects connection name.
  4. Line 27: Replace "On time" with the Closure field value configured in your portal.
  5. Line 40: Replace "Delayed" with the Closure field value configured in your portal.
  6. Lines 24, 25, 37, 39, and 41: Replace "days" with the API name of your number field if it has been renamed.
      9. Add the following arguments during configuration.



      10. Click Save.
      11. Navigate to   → Automation → Workflow Rules.
      12. Click the Tasks tab in the upper navigation panel and click New Workflow Rule.
      13. Select Based on User Action as the execution condition and execute the rule when a task is Updated.
      14. Click Add Criteria+ and set the following criteria:
    1. Task Status Is Completed
    2. AND Stop Is Disabled
Notes
If you have configured a Custom Status or using the default Closed status, ensure the Task Status in the Workflow Rule criteria is set to match your portal configuration.
      15. Click +Add Action and select Update Field. Set Status to custom status Re Open.
      16. Click +Add Action again and select Associate Custom Function. Select the custom function created previously.



      17. Click Save Rule.
      18. Toggle the Workflow Rule Status on to enable it.



With this automation in place, teams can automatically track on-time and delayed tasks along with overdue days. This gives project managers better visibility into delivery timelines.

If you have any questions, feel free to drop a comment below or reach out to us at support@zohoprojects.com.