Power of Automation :: Automatically divide the work hours between the task owners

Power of Automation :: Automatically divide the work hours between the task owners

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. 

Let us consider the below use case from a customer - 

As per the design, Work hours will be allocated based on the number of owners assigned to a task. For example, A task is added with the duration of 16 hours and assigned to a user, John. So, the work hours allotted for him will be 16 hours. If one more owner is added to the same task, the work hours gets doubled and the total work hours will be 32. 

But we have received a specific use case from a customer and he wanted to allocate the work hours at task level instead of individual user level.

From the above scenario, he wants the work hours '16' to be equally divided between the task owners rather than doubling it to 32.

We resolved this use case using Custom functions in Zoho Projects

Todo : Create a connection for Zoho Projects service with the scopes “ZohoProjects.portals.READ”, “ZohoProjects.tasks.READ”, “ZohoProjects.tasks.UPDATE” to replace ‘connectionprojects’ with the connection name. Click this link below to learn how to create the connection. Attached the screenshots of Task Workflow Rule & Arguments.

Script to be used : 
  1. endPoint = "https://projects.zoho.com/restapi/portal/";
  2. updateTaskParameter = Map();
  3. ownerIds = "";
  4. isOwnerPresent = false;
  5. taskWorks = List();
  6. if((duration.contains(":")||duration.toNumber()!=0)&&affectedValues.get("action").containsIgnoreCase("Creation"))
  7. {
  8. // Get Task Details
  9. taskResponse = zoho.projects.getRecordById(portalId,projectId,"Tasks",taskId,"connectionprojects");
  10. owners = taskResponse.get("tasks").get(0).get("details").get("owners");
  11. workHours = taskResponse.get("tasks").get(0).get("work");
  12. workhour = workHours.toList(":").get(0).toNumber();
  13. workhour_mins = workHours.toList(":").get(1).toNumber();
  14. convertedMinsToHours = workhour_mins.toNumber() / 60;
  15. totalWorkHours = workhour + convertedMinsToHours;
  16. ownerCount = owners.size();
  17. for each  owner in owners
  18. {
  19. if(owner.get("name").containsIgnoreCase("Unassigned"))
  20. {
  21. break;
  22. }
  23. else
  24. {
  25. isOwnerPresent = true;
  26. ownerWorkHours = totalWorkHours / (ownerCount * ownerCount);
  27. taskWork = Map();
  28. taskWork.put("user_id",owner.get("id"));
  29. taskWork.put("working_hours",ownerWorkHours.round(2));
  30. taskWorks.add(taskWork);
  31. ownerIds = ownerIds + owner.get("id") + ",";
  32. }
  33. }
  34. taskOwners = ownerIds.removeLastOccurence(",");
  35. if(isOwnerPresent)
  36. {
  37. totalHours = totalWorkHours / ownerCount;
  38. updateTaskParameter.put("owner_work",taskWorks);
  39. updateTaskParameter.put("work_type","work_hours");
  40. updateTaskParameter.put("person_responsible",taskOwners);
  41. updateTaskResponse = zoho.projects.update(portalId,projectId,"tasks",taskId,updateTaskParameter,"connectionprojects");
  42. }
  43. }
  44. else
  45. {
  46. // Get Task Details
  47. taskResponse = zoho.projects.getRecordById(portalId,projectId,"Tasks",taskId,"connectionprojects");
  48. owners = taskResponse.get("tasks").get(0).get("details").get("owners");
  49. durationType = taskResponse.get("tasks").get(0).get("duration_type");
  50. duration = taskResponse.get("tasks").get(0).get("duration");
  51. if(durationType.containsIgnoreCase("hrs"))
  52. {
  53. totalHours = duration.toDecimal();
  54. }
  55. else
  56. {
  57. portalInfo = invokeurl
  58. [
  59. url :endPoint + portalId + "/"
  60. type :GET
  61. connection:"connectionprojects"
  62. ];
  63. businessHours = portalInfo.get("portals").get(0).get("settings").get("business_hours");
  64. business_start = businessHours.get("business_start");
  65. business_end = businessHours.get("business_end");
  66. businessTotalHours = (business_end - business_start) / 60;
  67. totalHours = duration.toDecimal() * businessTotalHours;
  68. }
  69. ownerCount = owners.size();
  70. for each  owner in owners
  71. {
  72. if(owner.get("name").containsIgnoreCase("Unassigned"))
  73. {
  74. break;
  75. }
  76. else
  77. {
  78. isOwnerPresent = true;
  79. ownerWorkHours = totalHours / ownerCount;
  80. taskWork = Map();
  81. taskWork.put("user_id",owner.get("id"));
  82. taskWork.put("working_hours",ownerWorkHours.round(2));
  83. taskWorks.add(taskWork);
  84. ownerIds = ownerIds + owner.get("id") + ",";
  85. }
  86. }
  87. taskOwners = ownerIds.removeLastOccurence(",");
  88. if(isOwnerPresent)
  89. {
  90. updateTaskParameter.put("owner_work",taskWorks);
  91. updateTaskParameter.put("work_type","work_hours");
  92. updateTaskParameter.put("person_responsible",taskOwners);
  93. updateTaskResponse = zoho.projects.update(portalId,projectId,"tasks",taskId,updateTaskParameter,"connectionprojects");
  94. }
  95. }
  96. return "success";
Watch this space for more such custom functions

    Access your files securely from anywhere

          Zoho Developer Community




                                    Zoho Desk Resources

                                    • Desk Community Learning Series


                                    • Digest


                                    • Functions


                                    • Meetups


                                    • Kbase


                                    • Resources


                                    • Glossary


                                    • Desk Marketplace


                                    • MVP Corner


                                    • Word of the Day



                                        Zoho Marketing Automation
                                                • Sticky Posts

                                                • Zoho Projects Roadshow, USA - 2024

                                                  Dear Users, We are happy to announce the Zoho Projects Roadshows 2024 in USA. This is an excellent opportunity to learn more about Zoho Projects and gain in-depth knowledge of the advanced features. Our team will also discuss industry specific solutions
                                                • Project Billing with the Staff Hours Method in Zoho Projects

                                                  The Staff Hours Billing Method in Zoho Projects allows you to bill your clients based on the actual time spent by each team member on a project, at the rate set for each user. This is useful for projects where different skill sets are needed and service
                                                • Tip 37: Time Log Restriction in Zoho Projects

                                                  Timesheet in Zoho Projects helps you big time in entering log hours for the tasks and issues and approving them. Now, with the new Time Log Restriction option, you can set daily and weekly log hour limits. You can restrict users from entering extra log hours than the permissible limit. The limits are restricted to 24 hours per day and 168 hours per week by default based on business hours. To customize, navigate to Task & Timesheet settings under Portal Configuration in Zoho Projects setup and enable
                                                • Organize and Track Phases with Phase Custom Views

                                                  Phase Custom Views let you filter and display phases based on specific criteria. This helps you focus on what’s most relevant for you and your team. Filter phases using criteria such as budget, status, and more. Share views with specific users or teams
                                                • Create Your Own Issue Management System

                                                  Effective issue management is a cornerstone of project success. Every bug or issue, no matter how small, needs to be tracked and resolved in time to maintain project momentum. In this post, we’ll explore how an issue management system in Zoho Projects


                                                Manage your brands on social media



                                                      Zoho TeamInbox Resources

                                                        Zoho DataPrep Resources



                                                          Zoho CRM Plus Resources

                                                            Zoho Books Resources


                                                              Zoho Subscriptions Resources

                                                                Zoho Projects Resources


                                                                  Zoho Sprints Resources


                                                                    Qntrl Resources


                                                                      Zoho Creator Resources



                                                                          Zoho Campaigns Resources


                                                                            Zoho CRM Resources

                                                                            • CRM Community Learning Series

                                                                              CRM Community Learning Series


                                                                            • Kaizen

                                                                              Kaizen

                                                                            • Functions

                                                                              Functions

                                                                            • Meetups

                                                                              Meetups

                                                                            • Kbase

                                                                              Kbase

                                                                            • Resources

                                                                              Resources

                                                                            • Digest

                                                                              Digest

                                                                            • CRM Marketplace

                                                                              CRM Marketplace

                                                                            • MVP Corner

                                                                              MVP Corner





                                                                                Design. Discuss. Deliver.

                                                                                Create visually engaging stories with Zoho Show.

                                                                                Get Started Now


                                                                                  Zoho Show Resources


                                                                                    Zoho Writer Writer

                                                                                    Get Started. Write Away!

                                                                                    Writer is a powerful online word processor, designed for collaborative work.

                                                                                      Zoho CRM コンテンツ






                                                                                        Nederlandse Hulpbronnen


                                                                                            ご検討中の方





                                                                                                  • Recent Topics

                                                                                                  • Need to send a single email to up to 20 recipients

                                                                                                    I want to send a single email to ~16 or 20 recipients. It appears that I cannot do this in Zoho email as it gets flagged as unusual activity. I need to be able to communicate with this group on a regular basis. What am I missing that Zoho doesn't allow
                                                                                                  • Unable to Schedule One-to-One Emails in Zoho CRM

                                                                                                    Hi everyone, I’m using the Zoho CRM Professional Edition and facing an issue with scheduling one-to-one emails directly from CRM. While I can send immediate emails without any problem, I don’t see an option to schedule these emails for a later time. I’ve
                                                                                                  • Canvas Detail View Related List Sorting

                                                                                                    Hello, I am having an issue finding a way to sort a related list within a canvas detail view. I have sorted the related list on the page layout associated with the canvas view, but that does not transfer to the canvas view. What am I missing?
                                                                                                  • Repeatable Fields/Sections in Zoho CRM

                                                                                                    Hi Zoho Team, We have a module in CRM named "Clients". We would like to know whether it is possible to have a feature enables us to have repeatable sections in our clients' profiles? For example, if we customized a section in the clients' profiles named
                                                                                                  • Zoho Analytics: Requests for view access

                                                                                                    Hello, We have a user that might request access to a certain view, report etc. However this request for access is being sent to different admins within the workspace, is is possible to set who the "approver" is of these requests? If not what are the rules
                                                                                                  • Boolean Fields in Mail Merge Displaying as Checkmarks

                                                                                                    I'm really liking the new mail merge functionality. It's replaced the Zoho Sign extension for us. One problem I've seen is that boolean operators (i.e. Checkbox fields) in CRM merge as "True" or "False". This looks a little ugly in my final document — is there a way I can get those to display as checkboxes?
                                                                                                  • Formula in Sub Form

                                                                                                    Hello - I have created a sub-form and the data is going to be insurance policy information. However some of the policy amounts are based on a percentage of a main coverage. For example, Debris removal coverage is 5% of the main dwelling policy. Is there
                                                                                                  • Email alias already exist

                                                                                                    Hello, I'm getting an error message the email alias already exist when attempting to add 2 email addresses. The emails are associated with an account I deleted. I started a new account and need to add them back to get 1 email at each. I have an open ticket
                                                                                                  • Migrate emails from a shared mail box to a private mail box

                                                                                                    How is possible migrate a shared mail box if the migration tool require a password, and the shared mail dosent have ?
                                                                                                  • Support poor service

                                                                                                    I just wanted Zoho support to give me some more concrete answers. I’m facing SMTP error issues, and they told me that the South American IP was experiencing problems, but they didn’t provide an estimate for when it would be resolved. Now my company is
                                                                                                  • Zoho say my domain seems to be already associated with another account

                                                                                                    I created a zoho account for try my domain mail configuration. When I want to add my domain in this page https://mailadmin.zoho.com/hosting?plan=free then this shows an error that is "This domain is already associated with this account a*****n@f*****."
                                                                                                  • Incorrect Device Time

                                                                                                    Hi On my windows laptop I can't sign into Zoho mail due to "incorrect device time". I'm in Toronto, Canada. How can this be resolved?
                                                                                                  • Get user images by API

                                                                                                    Hi For our internal management software, I want to retrieve user photos via REST API: curl --location --request GET 'https://profile.zoho.com/file?fs=thumb&ID=<zoid>' \ --header 'Authorization: Zoho-oauthtoken <token>' The token has `profile.userphoto.ALL`,
                                                                                                  • Depois de 1 ano não consigo receber e-mail

                                                                                                    Consigo enviar e-mails mas não estou recebendo nenhum e-mail isso aconteceu pontualmente após eu completar 1 ano de uso. Me ajudem por favor
                                                                                                  • Submitted form URL

                                                                                                    I am using the feature "Include a link to allow respondents to edit their responses" for the first time. This URL is included in the email sent to the user after they press Submit. If a form is Saved, there is a section called Partially Saved Entries
                                                                                                  • API to post drafts for social media

                                                                                                    I we want to post draft posts to our zoho social account and then approve and schedule them within Zoho social. is this possible with for example: https://apis.zoho.com/social/v2/post TIA Jon
                                                                                                  • Function for Emails tranfer from Lead to Deal

                                                                                                    Hi Due to the fact that my Deals conversion needs to be done in 2 ways - depending on the fact if those records already exists or not - resources in fields are different. I am making function control conversation for Leads but I have problem with transferring
                                                                                                  • Create a new immigration service- Similar to immigration law software

                                                                                                    It will be good if you can build a new service. Data will be pulled from the employee form. Then automatically users should be able to complete immigration forms like I 129, ETA 9089, ETA 9035 E, G- 28, W4, I 9 PDF forms and then be able to send for signature with Zoho sign. Immigration Softwares like docketwise can be used for ideas. The advantage with this it sits within Zoho people and employees don't have to feed data in another system
                                                                                                  • Accessibility in Zoho CRM: Not just a feature—a way to empower

                                                                                                    For instructions on setting up these controls, please check this help document: Configuring accessibility controls. Hello everyone, Today (December 3, 2024), on the International Day of Persons with Disabilities, we begin our journey towards a CRM that
                                                                                                  • Zoho Meeting very bad video quality

                                                                                                    Hello, I need 1080p HD on my Zoho Meeting as explained here: Low Resolution/Quality Video (zoho.com) Currently, video quality is lagging with 400mb internet which is not acceptable for my business. My 1080p 60FPS webcam performs well on platforms like
                                                                                                  • Contacts with Deals not appearing.

                                                                                                    What: I simply want to see all of the contacts that are tied to an open deal Problem: In Contacts Module > When filtering on Contacts with an open deal, Zoho only shows some Contacts instead of all. Details: More specifically, I should have ~200 contacts
                                                                                                  • Auto-sync field of lookup value

                                                                                                    This feature has been requested many times in the discussion Field of Lookup Announcement and this post aims to track it separately. At the moment the value of a 'field of lookup' is a snapshot but once the parent lookup field is updated the values diverge.
                                                                                                  • CRM limit reached: only 2 subforms can be created

                                                                                                    we recently stumbled upon a limit of 2 subforms per module. while we found a workaround on this occasion, only 2 subforms can be quite limiting in an enterprise setting. @Ishwarya SG I've read about imminent increase of other components (e.
                                                                                                  • Version of Cliq included with Zoho One and Limitations

                                                                                                    I'm confused by the information presented in the application detail page of Zoho One. I'm a solopreneur with a single-seat Zoho One Enterprise license and I need to communicate externally .. extensively. The plan details page suggests channels are limited to 100 members. Whereas the pricing plan comparison page on the Cliq marketing site says 2500 for enterprise level.  If it's 100... that's going to kill my use case as it is my understanding that external customers can only be communicated with
                                                                                                  • Resubmit for Approval for Zoho Books Module in CRM

                                                                                                    The integration between CRM and Books is great, but it is incomplete in many areas. One of them is if an estimate/invoice/sales order is rejected, the users in CRM cannot resubmit it for approval. Let's face it, sales people will mostly be in CRM and
                                                                                                  • Upload edited meeting recording for attendees to download

                                                                                                    Hi Would it be possible to let meeting organisers upload an edited version of the meeting recording? Usage case: most of us probably start a meeting 15 minutes before the official start time. It would be nice to trim that dead time off the recording.
                                                                                                  • Why does the embed feature within the article editor seem to be not functional?

                                                                                                    I would like to embed media into an article, but that feature seems to be non-functioning. Am I doing something wrong? to clarify, I do not want to create an article by embedding. I want to embed media into an article I have created in a manual.
                                                                                                  • Get all fields using COQL

                                                                                                    Hi Is it possible to get all the fields of a record using COQL?. Something similar to select * from Accounts in SQL.
                                                                                                  • Mapping a new Ticket in Zoho Desk to an Account or Deal in Zoho CRM manually

                                                                                                    Is there any way for me to map an existing ticket in Zoho desk to an account or Deal within Zoho CRM? Sometimes people use different email to put in a ticket than the one that we have in the CRM, but it's still the same person. We would like to be able
                                                                                                  • Can it change the language ?

                                                                                                    Hello ! The question is in the title ;) 
                                                                                                  • Notes and Notebook integration

                                                                                                    Maybe I missed it, but is there a way to synch notes in the desktop with the notes in the Notebook app? I've been combing through the help topics and other forum entries and not finding anything. When I downloaded the android app I assumed there was integration with the desktop notes. Is that not the case? thanks.
                                                                                                  • Text formatting does not work (Notebook Mac)

                                                                                                    The text formatting does not work at all. It seems, that the program loses the selection and therefore hitting bold, italic, etc. does not do anything.
                                                                                                  • For Each Loop only returns 1st result of List, not the whole list?

                                                                                                    I have a custom function that collects event data from Google calendar using invokeURL. I want to create meetings in CRM from this URL response. The invokeURL response contains over 100 records and works perfectly (code line 2). Then I'm using a For Each
                                                                                                  • Delete Zoho Mail Account accidently from Admin panel

                                                                                                    Is it possible to restore deleted email accounts with all data.
                                                                                                  • How do I delete a test email address to which I am supposed to send a test email?

                                                                                                    How do I delete an email address added to a test email recipient that is no longer needed due to resignation or other reasons?
                                                                                                  • Kaizen #121 : Customize List Views using Client Script

                                                                                                    Hello everyone! Welcome back to another interesting Kaizen post. In this post, we can discuss how to customize List Views using Client Script. This post will answer the questions Ability to remove public views by the super admin in the Zoho CRM and Is
                                                                                                  • Batch Number on Packing Slip

                                                                                                    When we send orders to our warehouse, we want to tell them the batch number to pull from the shelf.  It seems we should be able to pick the batch when assembling the package. In the current Inventory, we have to create an invoice, pick batches for the invoice.  This is too late.   As a workaround, we are sending the invoice to the warehouse (via a template that removes most of the price information).  This is cumbersome and causes our warehouse to see the total invoice price (which can't be removed
                                                                                                  • Editing a bundle

                                                                                                    How can I edit a bundle?
                                                                                                  • Saving URL for Submitted Forms

                                                                                                    The unique URL for submitted forms should be saved automatically within 'System Fields'. (without sending a duplicate email to myself, there is no other way to retrieve the unique URL for a submitted form if the user wishes to update) Additionally, it
                                                                                                  • Implement Meeting Polls in Zoho Bookings

                                                                                                    Dear Zoho Bookings Support Team, We'd like to propose a feature enhancement related to appointment scheduling within Zoho Bookings. Current Functionality: Zoho Bookings excels at streamlining individual appointment scheduling. Users can set availability
                                                                                                  • Next Page