Power of Automation :: Automatic Task Status Handling for Users

Power of Automation :: Automatic Task Status Handling for Users

Hello Everyone,


A custom function is a software code that can be used to automate a process and this allows you to automate a notification, call a webhook, or perform logic immediately after a workflow rule is triggered. This feature helps to automate complex tasks and calculations. 


Below is the use case ::

Each user may have only one task in the “In Progress” status at any given time.

When a new task is set to “In Progress,” any other task currently in the same status for that user shall be automatically updated to “On Hold.”

The Hold Reason field should be automatically populated with a message indicating the new task ID, for example “Automatically placed on hold because Task #123456 was set to In Progress.”

This functionality can be implemented using Custom Functions. First, establish a connection with the Zoho Projects service using the scopes 'ZohoProjects.tasks.ALL'.

Make sure to set the connection link name to ‘projects’ in the code provided below. The screenshot of Arguments & Task Workflow Rule is attached for reference.

projectsV3APIEndPoint = "https://projectsapi.zoho.in/api/v3";
projectsAPIEndPoint = "https://projectsapi.zoho.in/restapi";
statusName = "On Hold";

if(taskOwnerDetails.get(0).get("full_name").equalsIgnoreCase("Unassigned User")) {
return "Owner not assigned";
}
ownerId = taskOwnerDetails.get(0).get("zpuid");
usersParam = Map();
usersParam.put("user_type","active");
taskParam = Map();
// Create a custom view with all the open tasks that are not in "On Hold" status and replace it in the view_id variable below
viewId = "337480000003148137";
taskParam.put("view_id", viewId);
taskParam.put("filter",{ "criteria": [ { "field_name": "owner", "criteria_condition": "is", "value": [ownerId] } ], "pattern": "1" });
getAllTasks = invokeurl
[
url :projectsV3APIEndPoint + "/portal/" + portalId + "/tasks"
type :GET
parameters:taskParam
connection:"projects"
];
info getAllTasks;
if(getAllTasks.containsKey("tasks") && getAllTasks.get("tasks").size()>0) {
statusId = null;
/*  Close all tasks */
//Fetch task layouts
taskLayoutDetails = invokeurl
[
url :projectsAPIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/tasklayouts"
type :GET
connection:"projects"
];
// info taskLayoutDetails;
if(taskLayoutDetails != null && taskLayoutDetails.get("status_details") != null)
{
statusDetails = taskLayoutDetails.get("status_details");
for each  status in statusDetails
{
if(status.get("name").equalsIgnoreCase(statusName))
{
// Fetch task status id based on status name
statusId = status.get("id");
info status.get("name") + " : " + statusId;
break;
}
}
}
if(statusId != null)
{
taskIds = list();
for each  task in getAllTasks.get("tasks")
{
projectId = task.get("project").get("id");
taskId = task.get("id");
if(taskId.equals(currentTaskId)){
info "Skipped";
} else {
/*Update task status to On Hold*/
updateTaskMap = Map();
updateTaskMap.put("custom_status",statusId);
updateTaskResponse = zoho.projects.update(portalId,projectId,"tasks",taskId,updateTaskMap,"projects");
/*Add comment*/
addCommentMap = Map();
taskURL = projectsEndPoint+portalName+"#zp/task-detail/"+currentTaskId;
addCommentMap.put("comment","Moved to Hold automatically because Task <a href="+taskURL+">"+task.get("prefix")+"</a> was set to In Progress");
addComment = invokeurl
[
url :projectsV3APIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/tasks/" + taskId + "/comments"
type :POST
parameters:addCommentMap.toString()
connection:"projects"
];
}
}
}
else
{
return "Status not found";
}
}
return "success";
Creating custom functions in Zoho Projects is straightforward and well-documented. Zoho provides a range of built-in functions that you can use as a starting point, and you can also easily define your own functions using Zoho's scripting language, Deluge. Give it a try and see how it can save your time and boost your productivity!

Watch this space for more such custom function codes.
    • Sticky Posts

    • 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
    • Accessibility Spotlight Series - 1

      Every user interacts with products differently, what feels intuitive to one may be challenging for another. Addressing this, accessibility is built into Zoho Project's design philosophy. This helps users navigate and perform actions with ease irrespective
    • Customize User Invites with Invitation Templates

      Invitation Templates help streamline the invitation process by allowing users to create customized email formats instead of sending a one-size-fits-all email. Different invitation templates can be created for portal users and client users to align with
    • Zoho Projects - Q3 Updates | 2025

      Hello Users, The final quarter of the year 2025 has begun, and we at Zoho Projects are all set with a plan. New targets to achieve and new milestones to reach, influenced by the lasting imprint of the past quarter. 2025's Q3 saw some new features and
    • Introducing Version-3 APIs - Explore New APIs & Enhancements

      Happy to announce the release of Version 3 (V3) APIs with an easy to use interface, new APIs, and more examples to help you understand and access the APIs better. V3 APIs can be accessed through our new link, where you can explore our complete documentation,

    Nederlandse Hulpbronnen