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.
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.”
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 belowviewId = "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 :GETparameters:taskParamconnection:"projects"];info getAllTasks;if(getAllTasks.containsKey("tasks") && getAllTasks.get("tasks").size()>0) {statusId = null;/* Close all tasks *///Fetch task layoutstaskLayoutDetails = invokeurl[url :projectsAPIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/tasklayouts"type :GETconnection:"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 namestatusId = 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 :POSTparameters:addCommentMap.toString()connection:"projects"];}}}else{return "Status not found";}}return "success";