Hello Everyone,
A Custom function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as 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 update the status of the Project to Completed automatically once all the Tasks were closed. This can be achieved using Task Custom Functions along with Workflow rules in Zoho Projects.
Custom function code:-
paramMap = Map();
paramMap.put("index",0);
paramMap.put("range",2);
paramMap.put("status","notcompleted");
getAllTasks = zoho.projects.getRecords(portalId,projectId,"Tasks",paramMap,0,"projects");
if(getAllTasks.isEmpty())
{
updateStatusName = "zp.projstatus.completed";
projectDetails = invokeurl
[
url :projectsAPIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/"
type :GET
connection:"XXXXX"
];
info projectDetails;
info "-------------------------------------";
statusMap = Map();
if(projectDetails != null && projectDetails.get("projects") != null)
{
projectDetail = projectDetails.get("projects").get(0);
layoutDetails = projectDetail.get("layout_details");
projectLayoutId = layoutDetails.get("project").get("id");
info "projectLayoutId: " + projectLayoutId;
projectLayoutDetail = invokeurl
[
url :projectsAPIEndPoint + "/portal/" + portalId + "/module/projects/layouts/" + projectLayoutId + "/"
type :GET
connection:"XXXXX"
];
if(projectLayoutDetail != null && projectLayoutDetail.get("customstatus") != null)
{
projectStatus = projectLayoutDetail.get("customstatus");
for each status in projectStatus
{
statusMap.put(status.get("status_name"),status.get("status_id"));
}
}
info "statusMap : " + statusMap;
info "------------------------";
if(statusMap.containKey(updateStatusName))
{
updateProjectParamMap = Map();
updateProjectParamMap.put("custom_status",statusMap.get(updateStatusName));
projectDetail = invokeurl
[
url :projectsAPIEndPoint + "/portal/" + portalId + "/projects/" + projectId + "/"
type :POST
parameters:updateProjectParamMap
connection:"XXXXX"
];
info projectDetail;
info "-------------------------------------";
}
}
}
return "success";
Make sure to replace XXXXX with the Zoho Projects connection link name along with scopes: ZohoProjects.portals.READ, ZohoProjects.projects.UPDATE, ZohoProjects.projects.READ, ZohoProjects.tasks.READ.
Check
this link to learn how to create the connection. Please find the screenshot of the parameters to be mapped and sample Task workflow rules.
With the custom function code provided above, our customer effectively utilised Task custom functions in Zoho Projects which allowed them to automate Project completion, reducing time consumption and in turn increasing their business productivity.
We hope you found this post useful. If you have any questions, feel free to share them in the comments below.