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 wanted to email all the portal users with their list of daily Tasks which are in open status along with details like Project name, Task name, Task URL, start date, due date, status. Sample email notification screenshot is attached for reference.
All you need to do is schedule the frequency for how often the below custom function should be executed. Here is the help document to know more about Schedule Functions.
Custom function code:-
projectParam = Map();
projectParam.put("status", "active");
getAllProjects = invokeurl
[
url : projectsEndpoint +portalId+"/projects/"
type : GET
parameters : projectParam
connection : "XXXXXXX"
];
if(getAllProjects.containKey("projects"))
{
projects = getAllProjects.get("projects");
usersParam = Map();
usersParam.put("user_type", "active");
getAllUsers = invokeurl
[
url : projectsEndpoint+portalId+"/users/"
type : GET
parameters : usersParam
connection : "XXXXXXX"
];
if(getAllUsers.containKey("users"))
{
users = getAllUsers.get("users");
for each user in users
{
userId = user.get("id");
taskParam = Map();
taskParam.put("status", "open");
taskParam.put("owner", userId);
taskParam.put("time", "today");
getAllTasks = invokeurl
[
url : projectsEndpoint + portalId+"/mytasks/"
type : GET
parameters : taskParam
connection : "XXXXXXX"
];
if(getAllTasks!="")
{
tasks = getAllTasks.get("tasks");
taskRow = "";
for each task in tasks
{
taskRow = taskRow + "<tr> <td>" + task.get("project").get("name") + "</td> <td>" + task.get("name") + "</td> <td>" + task.get("link").get("self").get("url") + "</td> <td>" + task.get("start_date") + "</td> <td>" + task.get("end_date") + "</td> <td>" + task.get("status").get("name") + "</td> </tr>";
}
sendmail
[
from :zoho.loginuserid
to : user.get("email")
subject :"Today's tasks"
message :"<html> <style> table, th, td { border:1px solid black; border-collapse: collapse; } </style> <body> <h2>Today's Tasks</h2> <table style=\"width:100%\"> <tr> <th>Project Name</th> <th>Task Name</th> <th>Task URL</th> <th>Start date</th><th>Due date</th> <th>Status</th></tr> " + taskRow + " </table> </body> </html>"
]
info taskRow;
}
}
}
}
Make sure to replace XXXXXXX with the Zoho Projects connection link name with scope ZohoProjects.Tasks.READ, ZohoProjects.portal.READ, ZohoProjects.Users.READ. Check this link to learn how to create the connection. Please find the screenshot of sample schedule function attached for reference.
We hope you found this post useful. If you have any questions, feel free to share them in the comments below.
Writer is a powerful online word processor, designed for collaborative work.