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.
Let us consider the below use case -
The status of a Project should be automatically updated based on the count of milestones that are completed in that project. Below should be the status of the project according to the count of completed Milestones.
Yet to Initiate → When no milestone is completed.
In Progress → When at-least one milestone is completed.
Completed → When all the milestones are completed.
We had accomplished this requirement using Custom functions.
Create a connection for Zoho Projects service with the scopes “ZohoProjects.portals.READ, ZohoProjects.projects.ALL, ZohoProjects.milestones.READ” to replace ‘projects’ with the connection name. Click this link below to learn how to create the connection.
It is possible to automate this process by associating the custom function to the Task Workflow Rules. Attached the screenshots of Task workflow rule & Arguments.
Script to be used ::
projectsEndpoint = "https://projectsapi.zoho.com/restapi/portal/";
param = Map();
param.put("status","completed");
getMilestones = invokeurl
[
url :projectsEndpoint + portalId + "/projects/"+ projectId +"/milestones/"
type :GET
parameters:param
connection:"projects"
];
// info getMilestones;
statusName = "";
if(getMilestones == "") {
info "No milestones completed";
statusName = "Yet to Initiate";
}
else if (getMilestones.contains("milestones")) {
completedMilestones = getMilestones.get("milestones").size();
info "Completed Milestones : "+completedMilestones;
if(completedMilestones==1) {
statusName = "zp.projstatus.inprogress";
}
else {
param = Map();
param.put("status","notcompleted");
getNotCompletedMilestones = invokeurl
[
url :projectsEndpoint + portalId + "/projects/"+ projectId +"/milestones/"
type :GET
parameters:param
connection:"projects"
];
if(getNotCompletedMilestones=="") {
statusName = "zp.projstatus.completed";
} else {
notCompletedMilestones = getNotCompletedMilestones.get("milestones").size();
info "Not Completed Milestones : "+notCompletedMilestones;
}
}
}
info statusName;
/* Project status update */
if(statusName!="") {
projectDetails = invokeurl
[
url :projectsEndpoint + portalId + "/projects/" + projectId + "/"
type :GET
connection:"projects"
];
// 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 :projectsEndpoint + portalId + "/module/projects/layouts/" + projectLayoutId + "/"
type :GET
connection:"projects"
];
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(statusName))
{
updateProjectParamMap = Map();
updateProjectParamMap.put("custom_status",statusMap.get(statusName));
projectDetail = invokeurl
[
url :projectsEndpoint + portalId + "/projects/" + projectId + "/"
type :POST
parameters:updateProjectParamMap
connection:"projects"
];
// info projectDetail;
// info "-------------------------------------";
}
}
}
return "success";
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.