Welcome to Portal
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.
Below is the requirement:
We had accomplished this requirement using Schedule functions. This allows you to execute custom functions based on a specified schedule such as hourly, daily, weekly, or monthly. This feature can be used for recurring actions, like generating monthly reports or sending automated emails to portal users about upcoming public milestones or deadlines without relying on specific events.
Create a connection for the Zoho Projects service with the scopes "ZohoProjects.timesheets.ALL' to replace ‘projects’ with the connection name. Click this link below to learn how to create the connection. Attached a screenshot of the Schedule Function for reference.
Script to be used:
endPointV3 = "https://projects.zoho.com/api/v3/portal/";
logParamList = List();
moduleTemplate = Map();
moduleTemplate.put("type","task");
timesheetParam = Map();
timesheetParam.put("view_type","month");
timesheetParam.put("module",moduleTemplate);
timesheetParam.put("start_date",zoho.currentdate.addMonth(-1));
timesheetParam.put("end_date",zoho.currentdate);
taskTimesheetResponse = invokeurl
[
url :endPointV3 + portalId + "/timesheet"
type :GET
parameters:timesheetParam
connection:"projects"
];
// info taskTimesheetResponse;
if(taskTimesheetResponse != null)
{
for each time_log in taskTimesheetResponse.get("time_logs")
{
for each logs in time_log.get("log_details")
{
logDetail = Map();
logDetail.put("approval_status","approved");
logDetail.put("module","task");
logDetail.put("id",logs.get("id"));
logParamList.add(logDetail);
}
}
}
genralLogIds = Map();
moduleTemplate.clear();
timesheetParam.remove("module");
moduleTemplate.put("type","general");
timesheetParam.put("module",moduleTemplate);
generalTimesheetResponse = invokeurl
[
url :endPointV3 + portalId + "/timesheet"
type :GET
parameters:timesheetParam
connection:"projects"
];
// info generalTimesheetResponse;
if(generalTimesheetResponse != null)
{
for each time_log in generalTimesheetResponse.get("time_logs")
{
for each logs in time_log.get("log_details")
{
logDetail = Map();
logDetail.put("approval_status","approved");
logDetail.put("module","general");
logDetail.put("id",logs.get("id"));
logParamList.add(logDetail);
}
}
}
issueLogIds = Map();
moduleTemplate.clear();
timesheetParam.remove("module");
moduleTemplate.put("type","issue");
timesheetParam.put("module",moduleTemplate);
issueTimesheetResponse = invokeurl
[
url :endPointV3 + portalId + "/timesheet"
type :GET
parameters:timesheetParam
connection:"projects"
];
// info issueTimesheetResponse;
if(issueTimesheetResponse != null)
{
for each time_log in issueTimesheetResponse.get("time_logs")
{
for each logs in time_log.get("log_details")
{
logDetail = Map();
logDetail.put("approval_status","approved");
logDetail.put("module","issue");
logDetail.put("id",logs.get("id"));
logParamList.add(logDetail);
}
}
}
approveTimesheets = invokeurl
[
url :endPointV3 + portalId + "/logs"
type :PATCH
parameters: "["+logParamList.toString()+"]"
connection:"projects"
];
info approveTimesheets;
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.
Subscribe to receive notifications from this topic.