Hello Everyone,
A Custom Function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as to when to trigger using the Workflow rules (be it Tasks / Project) and associate the custom function to it.
Requirement:-
One of our customers wanted to automatically sync the highest completion percentage from subtasks to the main task for better progress tracking.
For example, if Task A has subtasks B, C, and D, and subtask C is 80% complete (the highest), then Task A should also show 80% as its completion. This requirement was accomplished using Task custom functions along with workflow rules.
However, please note upon completion of the subtask (i.e if the subtask percentage is updated to 100) then all related tasks, including the main task, will be automatically marked as closed.
Below is the custom function code to be used.
Custom function code:-
// Get Task Details
taskResponse = zoho.projects.getRecordById(portalId,projectId,"Tasks",taskId,"XXXXX");
if(taskResponse.get("tasks").get(0).containKey("parent_task_id"))
{
parentTaskId = taskResponse.get("tasks").get(0).get("parent_task_id");
taskResponse = zoho.projects.getRecordById(portalId,projectId,"Tasks",parentTaskId,"XXXXX");
parentTaskPercentComplete = taskResponse.get("tasks").get(0).get("percent_complete");
if(parentTaskPercentComplete.toLong() < completionPercent.toLong()){
updateTaskParameter = Map();
updateTaskParameter.put("percent_complete",completionPercent.toLong());
updateTaskResponse = zoho.projects.update(portalId,projectId,"tasks",parentTaskId,updateTaskParameter,"XXXXX");
}
}
return "success";
Make sure to replace XXXXX with the Zoho Projects connection link name along with scopes: Zohoprojects.Tasks.ALL. Check this link to learn how to create the connection. Please find the screenshot of the parameters to be mapped and sample Task workflow rule.
We hope you found this post useful. If you have any questions, feel free to share them in the comments below.