Power of Automation:: Daily Time log summary broadcast to Zoho Cliq using Schedule Custom Functions

Power of Automation:: Daily Time log summary broadcast to Zoho Cliq using Schedule Custom Functions


Hello Everyone,

A Custom function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as when to trigger using the Workflow rules (be it Tasks / Project) and associate the custom function to it.

Requirement:

One of our customers would like to calculate the total time logs added by each developer at 11:59 PM and post a summary message in a specific Zoho Cliq channel along with the developer's name and email address as shown below. This was accomplished using Schedule Custom Functions.    



Custom function code:
 
/* TODO
*Replace the channel Unique Name (Line 4)
*Replace the email ids i.e user email in the criteria  (Line 8)*/
portalId = "XXXXXX";
endPointV3 = "https://projects.zoho.com/api/v3/portal/";
channelUniqueName = "testchannelpeq";
userParam = Map();
userParam.put("filter",{"criteria":{{"cfid":"4","criteria_condition":"contains","value":{"user email 1"}},{"cfid":"4","criteria_condition":"contains","value":{"user email 2"}},{"cfid":"4","criteria_condition":"contains","value":{"user email 3"}},{"cfid":"4","criteria_condition":"contains","value":{"user email 4"}},{"cfid":"4","criteria_condition":"contains","value":{"user email 5"}},{"cfid":"4","criteria_condition":"contains","value":{"user email 6"}}},"pattern":"1 OR 2 OR 3 OR 4 OR 5 OR 6"});
getUserInfo = invokeurl
[
url :endPointV3 + portalId + "/users"
type :GET
parameters:userParam
connection:"YYYYYY"
];
// info getUserInfo;
userAndLoghours = List();
for each  user in getUserInfo.get("users")
{
/* Get all time logs*/
moduleTemplate = Map();
moduleTemplate.put("type","task");
timesheetParam = Map();
timesheetParam.put("view_type","day");
timesheetParam.put("module",moduleTemplate);
timesheetParam.put("start_date",zoho.currentdate);
timesheetParam.put("filter",{"criteria":{{"field_name":"user","criteria_condition":"is","value":{user.get("id")}}},"pattern":"1"});
taskTimesheetResponse = invokeurl
[
url :endPointV3 + portalId + "/timesheet"
type :GET
parameters:timesheetParam
connection:"YYYYYY"
];
info taskTimesheetResponse;
if(!taskTimesheetResponse.get("time_logs").isEmpty())
{
log = Map();
log.put("display_name",user.get("display_name"));
log.put("email_id",user.get("email"));
log.put("full_name",user.get("full_name"));
log.put("log_hours",taskTimesheetResponse.get("log_hours").get("total_hours"));
userAndLoghours.add(log);
}
}
/*  Send message to channel*/
if(userAndLoghours.size() > 0)
{
response = Map();
slidesList = list();
slidesList0 = Map();
slidesList0.put("type","table");
slidesList0.put("title","Log hours of developer");
data = Map();
headersList = list();
headersList.add("Developer");
headersList.add("Email");
headersList.add("Logged Hours");
data.put("headers",headersList);
rowsList = list();
for each  details in userAndLoghours
{
rowsList0 = Map();
rowsList0.put("Developer",details.get("full_name"));
rowsList0.put("Email",details.get("email_id"));
rowsList0.put("Logged Hours",details.get("log_hours"));
rowsList.add(rowsList0);
}
data.put("rows",rowsList);
slidesList0.put("data",data);
slidesList.add(slidesList0);
response.put("slides",slidesList);
response.put("text",zoho.currentdate.toString("dd-MMM-yyyy"));
info response;
chat = zoho.cliq.postToChannel(channelUniqueName,response,"YYYYYY");
}
 
Make sure to replace XXXXX with your Portal Id and YYYYYY with Zoho Oauth connection link name along with scopes: ZohoProjects.users.READ, ZohoProjects.timesheets.READ, ZohoCliq.Webhooks.CREATE. Please find the screenshot of the sample Schedule function for reference.

We hope you found this post useful. If you have any questions, feel free to share them in the comments below.