Automation Series: Mandatory Time Logging Before Task Closure

Automation Series: Mandatory Time Logging Before Task Closure

In a project, when users work on multiple tasks simultaneously, they track time in different ways, either by starting a timer or by adding a time log. Sometimes users may forget to add time, which can lead to discrepancies in the timesheet.

When timesheets have incorrect time logs, the billable amount might not reflect the true budget and can lead to inaccurate billing. CodeX Script addresses this by displaying a custom message, forcing the user to add a time log before they update the status of a task.

Let's consider a law firm where associate attorneys move between Client Consultations and Case Reviews. During a consultation session, an associate might start a timer and update the task status to Under Review without logging the time. With this Codex Script, a message is triggered while attempting a status change to Under Review, keeping the task in the existing status until the time is logged.

To configure this in your Zoho Projects portal,

      1. Navigate to the upper-right corner of the page and click  → Developer Space → Connections.
      2. Click Create Connection, choose Zoho Projects as the service, and add the following scope:
  1. ZohoProjects.timesheets.READ
      3. Navigate to Developer Space → CodeX Scripts.
      4. Click Create CodeX Script in the upper-right corner.
      5. Enter the CodeX Script Name.
      6. Select the required Module, Layout and Event as shown below.

Codex Script

      7. Add the following Codex script in the script editor.
  1. // scopes: ZohoProjects.timesheets.READ
  2. function main() {
  3. if (current.affectedFields.status) {
  4. if (current.affectedFields.status.newValue.name == "Under Review") {
  5. const url = `https://projects.zoho.eu/api/v3/portal/${current.org.zohoOrgId}/projects/${current.record.projectId}/timelogs`
  6. const request = new HttpRequest();
  7. request.url(url);
  8. request.method('get');
  9. request.params({ "view_type": "projectspan", "module": { "id": current.record.id, "type": "task" }, "page": "1", "per_page": "200" });
  10. request.connection('connectionprojects');
  11. const response = request.execute();
  12. if (response.asJson().statusMessage.responseText.time_logs.length == 0) {
  13. throw new ScriptError("Add timelog and complete the task");
  14. }
  15. }
  16. }
  17. }
Info
Line 4: Replace "Under Review" with the task status name configured in your portal.
Line 5: Replace the domain like AU, EU, CN, IN etc.in the URL to match your data centre
Line 10: Replace "connectionprojects" with your Zoho Projects connection name.
Line 12: Replace the Script Error message with the prompt text you want displayed to the user.
      8. Click Save to execute the script.



Once this is setup, time logging does not have to be yet another task to be remembered, keeping time logs complete and billing records accurate.

Do give this a try and let us know how it works for you in the comments below, or write to us at support@zohoprojects.com for any questions.