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 |
// 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.