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.
Requirement:
When the status of the first milestone is updated to ‘complete’ the status of the respective project should be automatically updated to ‘In Progress’. Likewise, once the status of the last milestone is set to ‘complete’ then that project status should be automatically updated to ‘Completed’.
We had accomplished this requirement using Custom functions.
Create a connection for Zoho Projects service with the scopes “ZohoProjects.Portals.ALL, ZohoProjects.projects.ALL, ZohoProjects.Milestones.ALL, ZohoProjects.tasks.Read” to replace ‘connectionprojects’ with the connection name. Click this link below to learn how to create the connection. Attached the screenshot of the Arguments.
Script to be used
endPointV3 = "https://projects.zoho.com/api/v3/portal/";
endPoint = "https://projects.zoho.com/restapi/portal/";
// Get Task Details
taskResponse = zoho.projects.getRecordById(portalId,projectId,"Tasks",taskId,"connectionprojects");
milestoneId = taskResponse.get("tasks").get(0).get("milestone_id");
// Get Milestone Details
milestoneResponse = zoho.projects.getRecordById(portalId,projectId,"milestones",milestoneId,"connectionprojects");
milestoneStatusName = milestoneResponse.get("milestones").get(0).get("status_det").get("name");
if(milestoneStatusName.containsIgnoreCase("Completed"))
{
getProjectDetails = invokeurl
[
url :endPoint + portalId + "/projects/" + projectId + "/"
type :GET
connection:"connectionprojects"
];
projectStatus = getProjectDetails.get("projects").get(0).get("status");
projectlayoutId = getProjectDetails.get("projects").get(0).get("layout_details").get("project").get("id");
if(projectStatus.containsIgnoreCase("ACTIVE")){
statusName = "in progress";
getProjectLayoutDetails = invokeurl
[
url :endPoint + portalId + "/module/projects/layouts/" + projectlayoutId + "/?module=Projects&moduleId=0"
type :GET
connection:"connectionprojects"
];
customStatus = getProjectLayoutDetails.get("customstatus");
for each status in customStatus
{
if(status.get("status_name").containsIgnoreCase(statusName))
{
statusId = status.get("status_id");
break;
}
}
projectsParameter = Map();
projectsParameter.put("custom_status",statusId);
updateProjectResponse = invokeurl
[
url :endPoint + portalId + "/projects/" + projectId + "/"
type :POST
parameters:projectsParameter
connection:"connectionprojects"
];
}
milestoneParameter = Map();
milestoneParameter.put("index",0);
milestoneParameter.put("range",25);
getMilestoneDetails = invokeurl
[
url :endPointV3 + portalId + "/projects/" + projectId + "/milestones/view"
type :GET
parameters:milestoneParameter
connection:"connectionprojects"
];
views = getMilestoneDetails.get("customview_list").get("default_views");
for each view in views
{
if(view.get("name").containsIgnoreCase("allopen"))
{
viewId = view.get("custom_view_id");
break;
}
}
viewMilestoneDetails = invokeurl
[
url :endPointV3 + portalId + "/projects/" + projectId + "/milestones/viewscount/" + viewId
type :GET
connection:"connectionprojects"
];
if(viewMilestoneDetails.get("view_count") == 0)
{
statusName = "Completed";
getProjectDetails = invokeurl
[
url :endPoint + portalId + "/projects/" + projectId + "/"
type :GET
connection:"connectionprojects"
];
projectlayoutId = getProjectDetails.get("projects").get(0).get("layout_details").get("project").get("id");
getProjectLayoutDetails = invokeurl
[
url :endPoint + portalId + "/module/projects/layouts/" + projectlayoutId + "/?module=Projects&moduleId=0"
type :GET
connection:"connectionprojects"
];
customStatus = getProjectLayoutDetails.get("customstatus");
for each status in customStatus
{
if(status.get("status_name").containsIgnoreCase(statusName))
{
statusId = status.get("status_id");
}
}
projectsParameter = Map();
projectsParameter.put("custom_status",statusId);
updateProjectResponse = invokeurl
[
url :endPoint + portalId + "/projects/" + projectId + "/"
type :POST
parameters:projectsParameter
connection:"connectionprojects"
];
}
}
return "success";
To automate this, we can configure a workflow rule with the trigger as updating the task status and criteria should be set as task status is closed then associate the custom function.
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.
Writer is a powerful online word processor, designed for collaborative work.