Power of Automation :: Automatically update the Work hours of a task based on Custom field Value

Power of Automation :: Automatically update the Work hours of a task based on Custom field Value

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. 


Lets take the below use case from a customer - 


They have created a custom field 'Task Type' at task level. Based on the value provided to that field, work hours should be automatically updated in that task. Below are the mappings between Task Type & Work Hours.


Task Type

Work Hours

AAIR

12 hours

Account Intel

32 hours

Competitor Intel

8 hours

Connects

8 hours

Custom Intel

9 hours

Deal Shortlisting

2 hours

IT Intel

4 hours

Priority Task

10 hours

Profiling

8 hours

Quarterly Analysis

16 hours

Win Loss

8 hours


This can be accomplished using the below code. Create a connection using the scopes “ZohoProjects.portals.READ, ZohoProjects.tasks.ALL, ZohoProjects.timesheets.READ” and update the connection name ‘******’ in the below code. Find the attached screenshot of the Arguments.

Here is the link to know how to create a connection.

// scopes: ZohoProjects.portals.READ, ZohoProjects.tasks.ALL, ZohoProjects.timesheets.READ

workhourMapping = Map();
workhourMapping.put("AAIR", 12);
workhourMapping.put("Account Intel", 32);
workhourMapping.put("Competitor Intel", 8);
workhourMapping.put("Connects", 8);
// workhourMapping.put("Custom Intel", Yet to decide);
workhourMapping.put("Deal Shortlisting", 2);
workhourMapping.put("IT Intel", 4);
// workhourMapping.put("Priority Task", Yet to decide);
workhourMapping.put("Profiling", 8);
workhourMapping.put("Quarterly Analysis", 16);
workhourMapping.put("Win Loss", 8);
if(taskType==null || !workhourMapping.containKey(taskType)) {
return "Task type is empty or map doesn't contain the specified task type";
}
else {
taskResponse = zoho.projects.getRecordById(portalId,projectId,"Tasks",taskId,"projects");
owners = taskResponse.get("tasks").get(0).get("details").get("owners");
// info owners;
taskWorks = List();
for each  owner in owners
{
if(owner.get("name").containsIgnoreCase("Unassigned"))
{
info "No owner found";
break;
}
else
{
isOwnerPresent = true;
ownerId = owner.get("id");
ownerWorkHours = workhourMapping.get(taskType);
taskWork = Map();
taskWork.put("user_id",ownerId);
taskWork.put("working_hours",ownerWorkHours);
taskWorks.add(taskWork);
break;
}
}
// info taskOwners;
updateTaskParameter = Map();
if(isOwnerPresent)
{
updateTaskParameter.put("owner_work",taskWorks);
updateTaskParameter.put("work_type","work_hours");
updateTaskParameter.put("person_responsible",ownerId);
updateTaskResponse = zoho.projects.update(portalId,projectId,"tasks",taskId,updateTaskParameter,"********");
info updateTaskResponse;
}
}
return "success";


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. 


    • Sticky Posts

    • Schedule Exports for Regular Project Updates

      Tracking project data often means exporting data at regular intervals. Instead of manually exporting data every time, users can schedule exports for Phases, Tasks, and Tasks in Zoho Projects. These exports can be set to run once, daily, weekly, or monthly
    • Set Custom Business Calendars and Holidays for Global Teams

      Managing a project across diverse teams means accounting for more than just tasks and deadlines; it means acknowledging how and when each team actually works. Users might follow different working days or observe region-specific holidays that cannot be
    • Introducing Version-3 APIs - Explore New APIs & Enhancements

      Happy to announce the release of Version 3 (V3) APIs with an easy to use interface, new APIs, and more examples to help you understand and access the APIs better. V3 APIs can be accessed through our new link, where you can explore our complete documentation,
    • Restore Trashed Records Anytime Within 30 Days

      Access the recycle bin from the Data Administration tab under the settings page in Zoho Projects, which gives better control over the trashed data. When records like projects, phases, task lists, tasks, issues, or project templates are trashed, they are
    • Organize and Clone Task Custom Views

      We have rolled out two new enhancements to task custom views: Custom View Groups and Custom View Clone. Custom View Groups Similar to predefined view groups, we have introduced groups for custom views to help organize and categorize them. My Custom Views: