Power of Automation :: Automatically update the Project status based on the Milestone status

Power of Automation :: Automatically update the Project status based on the Milestone status


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. 



      • Sticky Posts

      • Enhanced Collaboration and Global Web Tabs

        Hello Users, We are rolling out two key enhancements in Zoho Projects that will be part of our November release. Here’s what to expect: 1. Collaboration Section in the Left Navigation Panel What’s new? All communication and interactive tools will be grouped
      • Tip 37: Time Log Restriction in Zoho Projects

        Timesheet in Zoho Projects helps you big time in entering log hours for the tasks and issues and approving them. Now, with the new Time Log Restriction option, you can set daily and weekly log hour limits. You can restrict users from entering extra log hours than the permissible limit. The limits are restricted to 24 hours per day and 168 hours per week by default based on business hours. To customize, navigate to Task & Timesheet settings under Portal Configuration in Zoho Projects setup and enable
      • Rename Task Module To Suit Your Project

        Task Module in Zoho Projects gives a comprehensive view of all the action items, known as Tasks, across all projects. However, different industries may use alternative terminology for similar processes, which might not always be recognised when labelled
      • Project Billing with the Staff Hours Method in Zoho Projects

        The Staff Hours Billing Method in Zoho Projects allows you to bill your clients based on the actual time spent by each team member on a project, at the rate set for each user. This is useful for projects where different skill sets are needed and service
      • Achieve Full Financial Control by Tracking Both Cost Budget and Budgeted Hours

        Zoho Projects now supports tracking budget with both Cost Budget and Budgeted Hours simultaneously across all modules (Based on Project, Phase, Task, or User). Why Track Both? Tracking both cost budget and budgeted hours provides a more holistic view