Welcome to Portal

?Unknown\pull-down

Welcome to Zoho Cares

Bienvenido a Soporte de Zoho

Search our knowledge base, ask the community or submit a request.

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:-

Quote
One of our customers was tracking their Retail management using Zoho Projects and they wanted to track deadlines for vendor orders where the due dates for tasks are updated months in advance. They wanted a feature that automatically notifies the task owners five days before the due date to ensure timely order submission. This was achievable using the Schedule Functions in Zoho Projects.

  
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","all");
// taskParam.put("all_tasks", true);
getAllTasks = invokeurl
[
url :projectsEndpoint + portalId + "/mytasks/"
type :GET
parameters:taskParam
connection:"XXXXXXX"
];
if(getAllTasks != "")
{
tasks = getAllTasks.get("tasks");
taskRow = "";
// Get the current date
current_date = zoho.currentdate;
// Add 5 days to the current date
five_days_after = current_date.addDay(5);
for each  task in tasks
{
if(task.get("end_date")==five_days_after.toString()){
info "task date : "+task;
res = invokeurl [
url : task.get("link").get("self").get("url")
type : GET
connection : "XXXXXXX"
];
taskRow = taskRow + "<tr> <td>" + task.get("project").get("name") + "</td> <td>" + task.get("name") + "</td> <td>" + res.get("tasks").get(0).get("link").get("web").get("url") + "</td>  <td>" + task.get("start_date") + "</td> <td>" + task.get("end_date") + "</td> <td>" + task.get("status").get("name") + "</td> </tr>";
}
}
if(taskRow!=""){
sendmail
[
from :zoho.loginuserid
to :user.get("email")
subject :"Orders that are pending in  5 days"
message :"<html> <style> table, th, td { border:1px solid black; border-collapse: collapse; } </style> <body> <h2>Orders that are pending in  5 days</h2> <table style=\"width:100%\"> <tr> <th>Project Name</th> <th>Order Name</th> <th>Order URL</th>  <th>Start date</th><th>Due date</th>  <th>Status</th></tr> " + taskRow + " </table> </body> </html>"
]
}
}
}
}
}
InfoAll you have to do is to replace XXXXXXX with the Zoho Projects connection link name which has the scopes: ZohoProjects.users.ALL, ZohoProjects.portals.ALL, ZohoProjects.projects.ALL, ZohoProjects.tasks.ALL in the below codeCheck this link to learn how to create the connection.Please find the screenshots of the parameters to be mapped and 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.


Attachments
Schedule Function .png
Schedule Function .png942 KB
1 user likes this announcement.
3 Replies
Reply
  • 30 days ago

Hello,

Thanks a lot. However, I think that we can achieve this requirement without code and using task workflows, because task workflows include now the possibility to trigger actions basing on a date. 

Thanks.

François, CoperBee

Dear François, 

It is possible to achieve this to some extent using Task Workflow rules based on date and time triggers. However, we recommend using the Schedule function for easier implementation for the following reasons:

Universal Configuration:

Time-based workflow rules can only be set for a specific layout, while the Schedule function only needs to be configured once for all layouts and projects.

Consolidated Notifications:

Task Workflow rules send separate notifications for each task, which can flood the task owners' inboxes. In contrast, the Schedule function consolidates all tasks due in the next five days into a single email, reducing inbox clutter. I have also attached a sample email notification screenshot for reference. 

Hope this clarifies. 

Regards,
Saraswathi.


Sample emal notification .png
Sample emal notification .png218 KB
  • 30 days ago

Excellent, thanks for your reply and for the function !

Reply to Saraswathi SA
/* */
  • 12
  • Insert
  • Plain text
Add Comment
(Up to 20 MB )