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 wants to automatically archive the projects after 60 days from its completion date. Same was achieved using the Schedule function feature available in Zoho Projects.
Below is the custom function code for reference.
Custom function code:-
days = 60;
currentDate = zoho.currentdate;
// get all custom Views
getAllCustomViewResponse = invokeurl
[
url :endPoint + portalId + "/module/projects/customview/"
type :GET
connection:"XXXXXXX"
];
customViews = getAllCustomViewResponse.get("default_views");
for each customView in customViews
{
if(customView.get("name").containsIgnoreCase("completedprojects"))
{
customViewId = customView.get("custom_view_id");
break;
}
}
// get all delayed projects
getAllProjectsParam = Map();
getAllProjectsParam.put("custom_view_id",customViewId);
getAllProjectsParam.put("page",0);
getAllProjectsParam.put("per_page",100);
getAllProjectsParam.put("is_gantt",false);
getAllProjectResponse = invokeurl
[
url :endPointV3 + portalId + "/projects"
type :GET
parameters:getAllProjectsParam
connection:"XXXXXXX"
];
projectsList = getAllProjectResponse.get("data").get(0).get("entities");
if(getAllProjectResponse.get("view_count") > 0)
{
for each project in projectsList
{
projectId = project.get("id");
// get project details
getProjectDetailsResponse = invokeurl
[
url :endPoint + portalId + "/projects/" + projectId + "/"
type :GET
connection:"XXXXXXX"
];
projectEndDate = getProjectDetailsResponse.get("projects").get(0).get("completed_on");
daysDiff = toDate(projectEndDate).daysBetween(currentDate);
if(daysDiff >= days){
projectsParameter = Map();
projectsParameter.put("status","archived");
updateProjectResponse = invokeurl
[
url :endPoint + portalId + "/projects/" + projectId + "/"
type :POST
parameters:projectsParameter
connection:"XXXXXXX"
];
}
}
}
Make sure to replace XXXXXXX with the Zoho Projects connection link name which has the scopes 'ZohoProjects.portals.READ, ZohoProjects.projects.READ, ZohoProjects.projects.UPDATE. ALL'. Check this link to learn how to create the connection.
Also, a screenshot of the sample Schedule Function along with arguments to be mapped is attached for reference.
We hope you found this post useful. If you have any questions, feel free to share them in the comments below.