当项目被标记为“已完成”时,可能仍然存在一些未完成的任务,例如未标记为已完成的重复任务、不再相关的任务或项目结束后不再需要关注的任务。
为了确保项目反映其最终状态,您可以使用任务工作流程规则,在项目达到“已完成”状态后自动关闭所有未完成的任务。
要进行此设置,请执行以下步骤:
首先,使用以下权限范围创建与 Zoho Projects 的连接:
ZohoProjects.tasks.ALL
ZohoProjects.projects.READ
ZohoProjects.portals.READ
ZohoProjects.milestones.ALL
创建一个自定义函数并添加以下 Deluge 脚本。将“xxxxxxxxx”替换为您的 Zoho Projects 连接名称,并映射下面列出的参数。
以下脚本将删除任务重复项并关闭项目中的所有任务。在以下脚本中,连接名称为“closealltasks”。
/ 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 'xxxxxxxxx' with the connection name. Click this link below to learn how to create the connection.// Link - https://help.zoho.com/portal/en/kb/projects/integration/connections/articles/connections-23-5-2022#How_to_establish_a_Connection
// TODO: Replace the status name (Closed status type) in Line No. 6, if needed.
projectsAPIEndPoint = "https://projectsapi.zoho.com/restapi";
projectsv3APIEndPoint = "https://projectsapi.zoho.com/api/v3";
statusName = "Closed";
statusId = null;
/* Close all tasks */
//Fetch task layouts
taskLayoutDetails = invokeurl
[
url :projectsAPIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/tasklayouts"
type :GET
connection:"closealltasks"
];
// 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)
{
indexValue = 1;
rangeValue = 100;
loop = {1,2,3,4,5,6,7,8,9,10};
predStatusMap = Map();
// This loop fetches up to 300 tasks. Increase the count as needed, e.g., loop = {1,2,3,4,5}; to fetch 500 tasks.
for each i in loop
{
taskParameter = Map();
taskParameter.put("index",indexValue);
taskParameter.put("range",rangeValue);
taskParameter.put("status","notcompleted");
// info taskParameter;
taskResponse = zoho.projects.getRecords(portalId,projectId,"tasks",taskParameter,0,"closealltasks");
// info taskResponse;
if(taskResponse.containKey("tasks"))
{
taskIds = list();
for each task in taskResponse.get("tasks")
{
taskId = task.get("id");
if(task.get("is_recurrence_set"))
{
updateTaskParameter = Map();
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"}});
updateTaskResponse = zoho.projects.update(portalId,projectId,"tasks",taskId,updateTaskParameter,"closealltasks");
info updateTaskResponse;
}
if(task.containsKey("dependency") && task.get("dependency").containsKey("predecessor"))
{
predTasks = task.get("dependency").get("predecessor");
predList = list();
for each predTaskId in predTasks
{
predList.add(task.get("dependency").get("dependencyDetails").get(predTaskId).get("IS_COMPLETED"));
}
if(!predList.contains(false))
{
taskIds.add(taskId);
}
}
else
{
taskIds.add(taskId);
}
info "taskIds : " + taskIds;
}
bulkUpdateParams = Map();
bulkUpdateParams.put("taskids",taskIds.toText().remove("[").remove("]"));
bulkUpdateParams.put("status",{"id":statusId});
info bulkUpdateParams;
/* Bulk update */
taskBulkUpdate = invokeurl
[
url :projectsv3APIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/tasks/bulk-update"
type :PATCH
parameters:bulkUpdateParams.toString()
connection:"closealltasks"
];
info taskBulkUpdate;
}
else
{
break;
}
}
}
return "success";
参数映射:
portalId - Portal System ID
projectId - Project System ID
保存自定义函数后,创建一个工作流程规则,并进行以下设置:
规则保存后,每当项目被标记为“已完成”时,所有未完成的任务都会自动完成。这确保项目能够准确反映其真实的完成状态,避免手动清理,并使您的项目保持最新状态。