Automation Series: Percentage-based Time Allocation

Automation Series: Percentage-based Time Allocation

Employees in an organization work across several projects simultaneously. Their work hours are split among multiple tasks from different projects. Logging time for each task manually can lead to inconsistency, and the effort rarely gets divided equally. With percentage-based time allocation, you can set the share of an employee's hours that each task should receive. Once the split is applied on a recurring basis, billing stays accurate without manual accounting. 

Consider an audit firm where each client account is managed as an individual project. The associates in the firm work on multiple projects at the same time.  At the beginning of each contract, the senior auditor estimates each associate's capacity, assigns them to projects, and sets a fixed percentage of their working hours for each project. 

To automate time logging, the senior auditor records the percentage of total work hours for each associate in a custom module. A custom function calculates the allocated work hours based on the percentage and logs time for each associate. A weekly time-based workflow rule triggers the custom function until project completion.   

To configure this automation in your Zoho Projects portal:

      1. Navigate to the upper-right corner and click  → Customization → Modules and Tabs click New Module to create a Project Custom Module.

      2. Add the following fields to the module:
  1. Title field/Number Field - To store the allocation percentage.
  2. User Picklist - To assign the employee to the time log.

      3. Enter the percentage value in the Title field and select the respective user in the User Picklist field.
      4. Navigate to → Developer Space → Connections. Click Create Connection, choose Zoho Projects as the service, and add the following scopes:
  1. ZohoProjects.timesheets.CREATE
  2. ZohoProjects.custom_fields.READ
  3. ZohoProjects.portals.READ

Connection

      5. Navigate to Custom Functions under Developer Space and click the Projects tab in the top panel.
      6. Create a new Custom Function and add the below Deluge script.
Notes
Ensure the user picklist field has values for the custom function to execute as expected.
  1. // scopes: ZohoProjects.timesheets.CREATE, ZohoProjects.custom_fields.READ, ZohoProjects.portals.READ
  2. getModules = invokeurl
  3. [
  4. url :projectsEndpointV3 + "/portal/" + portalId + "/settings/modules"
  5. type :GET
  6. connection:"projectscustom"
  7. ];
  8. for each module in getModules
  9. {
  10. if(module.containskey("plural_name"))
  11. {
  12. isModulePresent = equalsIgnoreCase(module.get("plural_name"),moduleName);
  13. }
  14. else
  15. {
  16. isModulePresent = equalsIgnoreCase(module.get("singular_name"),moduleName);
  17. }
  18. if(isModulePresent == true)
  19. {
  20. moduleId = module.get("id");
  21. }
  22. }
  23. if(moduleId != null)
  24. {
  25. param = Map();
  26. param.put("project_id",projectId);
  27. getEntityList = invokeurl
  28. [
  29. url :projectsEndpointV3 + "/portal/" + portalId + "/module/" + moduleId + "/entities"
  30. type :GET
  31. parameters:param
  32. connection:"projectscustom"
  33. ];
  34. if(getEntityList.size() > 0)
  35. {
  36. params = List();
  37. for each entity in getEntityList
  38. {
  39. totalMinutes = (40 * 60 * entity.get("name").toDecimal()) / 40;
  40. hours = floor(totalMinutes / 60);
  41. minutes = totalMinutes % 60;
  42. logHours = hours.toLong().toString().leftPad(2).replaceAll(" ","0") + ":" + minutes.toLong().toString().leftPad(2).replaceAll(" ","0");
  43. param = Map();
  44. param.put("project_id",projectId);
  45. param.put("type","general");
  46. param.put("date",zoho.currentdate.toString("yyyy-MM-dd"));
  47. param.put("bill_status","Billable");
  48. param.put("log_name","Log filed");
  49. param.put("hours",logHours);
  50. param.put("owner_zpuid",entity.get("user_cf_api_name").get("zpuid"));
  51. param.put("status","Approved");
  52. params.add(param);
  53. }
  54. obj = Map();
  55. obj.put("log_object",params);
  56. getTimelog = invokeurl
  57. [
  58. url :projectsEndpointV3 + "/portal/" + portalId + "/addbulktimelogs"
  59. type :POST
  60. parameters:obj
  61. connection:"projectscustom"
  62. ];
  63. }
  64. }
  65. return "success";
Notes
Lines 4, 32, 61 - Replace "projectscustom" with your Zoho Projects connection name.
      7. Add the following arguments during configuration:

Argument
Value
projectsEndpointV3
portalId
Portal ID
projectId
Project ID
moduleName
Expense (or your custom module name)
user
API name of the User Picklist field
Info
  1. Ensure that the portal URL in the arguments align with your data centre. If not, the function may not execute as expected
  2. Replace moduleName value with the respective custom module name if you have renamed it.
      8. Click Save.
      9. Navigate to Customization → Layouts, select the required layout, and add a custom date field as per your preference, here it is Budgeting Date.
      10. Navigate to  → Automation → Workflow Rules. Click the Projects tab and click New Workflow Rule.
      11. Select Based on Date & Time as the execution condition. Configure the rest as below to execute it weekly until project completion. You can also change up the condition and criteria based on your requirements.

Workflow rule
      12. Click +Add Action and select Associate Custom Function. Select the custom function created previously.
      13. Click Save Rule and toggle the Workflow Rule Status on to enable it.

Time Logs
Info
This custom date field triggers the automation. It shifts by 7 days after each execution, ensuring weekly recurrence until project completion.
If you have any questions, feel free to drop a comment below or reach out to us at support@zohoprojects.com.