Kaizen #187 - Building a Timer and Worklog Widget (Part 1)

Kaizen #187 - Building a Timer and Worklog Widget (Part 1)



Howdy Tech Wizards!

Welcome back to a fresh week of Kaizen! 

This time, we are diving into a two-part series where you will learn how to build a Timer and Worklog Widget for Zoho CRM. This widget helps track active work time and log multitasking sessions using Zoho CRM APIs, Client Script, Functions, and Workflows.

Why It Matters?

Zoho CRM effectively captures stage/status transitions, like tracking when a case moves from Open to In Progress or On Hold. However, in dynamic work environments, employees juggle multiple work items and engage in impromptu tasks or conversations. 

Let’s take the On Hold status as an example. 

While it can be used to indicate pauses in progress, it does not always align with real-world workflows. Consider these scenarios:

Not all interruptions justify a status change 

Moving the case to On Hold for every minor detour (to clarify something with a colleague or respond to another emergency work item) would be impractical and could lead to under reporting actual work hours. Over time, this untracked effort adds up, creating a gap in visibility.

Frequent status changes may dilute their meaning 

In many teams, On Hold signifies a legitimate blocker like waiting on customer input or an external dependency. Using it frequently to reflect quick shifts in attention could compromise that clarity. 

A timer widget solves this by:
  • Capturing hands-on work items.
  • Logging context switches (unrelated tasks) with descriptive entries.
  • Feeding structured entries into a custom module for reporting and subform sync.

Business Scenario: IT Service Desk & Ticket Resolution

A tech support team uses the Cases module to resolve customer issues. Some tickets are straightforward; others require follow-ups, escalations, or cross-team coordination. While CRM timestamps (like stage transitions or picklist tracking) track when changes happen, they do not reflect how long someone actively worked on a case.

This Timer Widget can be the ultimate solution to track down the active time spent on each case through out the day.

What are we Building?

By the end of this two-part guide, you will know how to:
  • Build a timer widget to track time per task or any CRM record.
  • Log work sessions into a custom module every time the timer is started/stopped.
  • Automatically populate a subform in the corresponding record module using workflows and Deluge functions.
  • Leverage the Reports module to analyze work patterns, SLA adherence, and productivity trends.
 In Part I, we will focus on:
-> Building and configuring the Timer Widget.
-> Capturing each timed session as a record in a custom module.

Prerequisites

1. Create a Custom Module

Create a custom module named Timer Entries to log work details and generate reports from the Reports module. A new record will be added to this module each time a timer is started.

Set up the following custom fields in the Timer Entries module:

Custom Fields
Data Type
Start Time
DateTime
End Time
DateTime
Total Duration (in mins.)
Formula 
DateBetween(${Timer Entries.Start Time},${Timer Entries.End Time},'Minutes')
Related to Case
Lookup to Cases module
Work Description
Multi Line


2. Add a custom picklist option

Add a custom picklist option called In Progress to the Status picklist field in the Cases module for precisely identifying the status of the cases. 

Follow this Add/Remove Picklist Values help section for more details. 

3. Setup Custom Views for Contextual Filtering

To streamline the widget experience and ensure users only see relevant records to associate while tracking time, set up two smart custom views—one in the Cases module and another in the Timer Entries module. 

Active Cases View (Cases Module)

Create a custom view in the Cases module to list only the active tickets the logged-in user is working on. Use the following criteria tips:
  • Use the Status field to filter records with values like In Progress, On Hold, or Escalated.
  • Use the Case Owner field to show records that are assigned only to the currently logged-in user.
This view powers the drop-down inside the widget where users select the case they want to start the timer for.
Active Timers View (Timer Entries Module)

Set up a second custom view in the Timer Entries module to track entries where the timer has been started but not yet stopped. These represent active timers. Use the following logic for criteria:
  • The End Time field is empty (i.e., timer still running).
  • Timer Entry owner field matches the logged-in user.
This view is used internally by the widget to detect if a timer is already running and update the same entry once the timer is stopped.
Follow the Managing List View help page and use the specifications shown in the following image.

Building the Timer Widget 

Step -1: Review Basics

Refer to our earlier Kaizen on CLI Installation, Creating a Widget Project, and Internal hosting of the same.

Step 2 - Develop the Widget

After initializing your widget project using CLI, implement the timer logic:

Fetching Active Cases

On page load, the populateRecordsDropdown function initiates a Get Records API call to the Cases module, using the Active Cases custom view ID. This fetches all active case records assigned to the logged-in user. 

These records are then listed in a dropdown, allowing users to quickly select the relevant case they are about to work on.

async function populateRecordsDropdown() {
            const recordsDropdown = document.getElementById("moduleRecords");
            recordsDropdown.innerHTML = ""; 

            try {
                const recordsResponse = await ZOHO.CRM.API.getAllRecords({
                    Entity: casesModule,
                    cvid: casesCVID,
                    per_page: 10
                });

                if (recordsResponse.data && recordsResponse.data.length > 0) {
                    recordsResponse.data.forEach(record => {
                        const option = document.createElement("option");
                        option.value = record.id;
                        option.textContent = record.Subject || "Unnamed Record"; 
                        recordsDropdown.appendChild(option);
                    });
                } else {
                    const placeholderOption = document.createElement("option");
                    placeholderOption.value = "";
                    placeholderOption.textContent = "No records found";
                    placeholderOption.disabled = true;
                    placeholderOption.selected = true;
                    recordsDropdown.appendChild(placeholderOption);
                }
            } catch (error) {
                console.error("Error fetching records:", error);
            }
        }

Starting the Timer and Creating an Entry

Once the user starts the timer, The createRecord function triggers a Create Record API call to log the session in the Timer Entries custom module. The record captures the start time and the related case and description (if provided).

Even if no details are entered or case is selected, a timer entry is still created with the start time. This ensures that spontaneous work sessions are tracked and not lost.

async function createRecord(startTime) {
            try {
                const workDescription = document.getElementById("workDescription").value;
                const selectedRecordId = document.getElementById("moduleRecords").value;
                const selectedRecordText = document.getElementById("moduleRecords").options[
                    document.getElementById("moduleRecords").selectedIndex
                ].text;

                const data = {
                    Start_Time: startTime,
                    Owner: currentUserId,
                    Work_Description: workDescription,
                    Related_to_Case: selectedRecordId, 
                    Name: selectedRecordText 
                };

                const response = await ZOHO.CRM.API.insertRecord({
                    Entity: timerModule,
                    APIData: data
                });

                console.log("Start time recorded successfully");
            } catch (error) {
                console.error("Error creating record:", error);
            }
        }


Stopping the Timer and Updating the Entry

When the timer is stopped, the widget uses the Active Timer Entry custom view to locate the most recent Timer Entry record created by the logged-in user that does not have an end time. 

The updateRecord is then triggered to update that active entry using the Update Record API call. It updates the End time of the session and the related case, descriptions, if it was not already provided when the timer was started.

async function updateRecord(endTime) {
            try {
                const workDescription = document.getElementById("workDescription").value;
                const selectedRecordId = document.getElementById("moduleRecords").value;

                const response = await ZOHO.CRM.API.getAllRecords({
                    Entity: timerModule,
                    cvid: timerEntriesCVID,
                    per_page: 1
                });

                const latestRecord = response.data[0];
                if (latestRecord) {
                    const recordId = latestRecord.id;
                    const data = {
                        id: recordId,
                        End_Time: endTime,
                        Work_Description: workDescription,
                        Related_to_Case: selectedRecordId 
                    };

                    await ZOHO.CRM.API.updateRecord({
                        Entity: timerModule,
                        APIData: data,
                        RecordID: recordId
                    });
                    console.log("End time updated successfully");
                }
            } catch (error) {
                console.error("Error updating record:", error);
            }
        }

Step 3 - Validate and Pack the Widget

  • Follow the steps given in the Widget help page to validate and package the widget.
  • Go to Zoho CRM > Setup > Developer Hub > Widgets and click Create New Widget.
  • Fill in the required details as shown in this image and ensure to select Button as the widget type.

Step 4 - Associate it with Flyout

  • Go to Setup > Developer Space > Client Script. Click New Script.
  • Enter a name and description for the script. Choose Command type in Category

  • Create a Flyout and render a widget within it using its details like the API name of the widget, title, size, and animation type. You can get the Widget API name from the widget's detail page. 
let allowedUserEmails = [];
allowedUserEmails.push('user1_email_address');
allowedUserEmails.push('user2_email_address');
allowedUserEmails.push('user3_email_address');
let currentUserEmail = $Crm.user.email;
if (allowedUserEmails.indexOf(currentUserEmail) == -1) {
    ZDK.Client.showMessage('Command access resticted', { type: 'error' });
    return false;
}
ZDK.Client.createFlyout('myFlyout', {header: 'Timer', animation_type: 4, height: '600px', width: '500px', top: '10px', left: '10px', bottom: '10px', right: '10px' });
ZDK.Client.getFlyout('myFlyout').open({ api_name: 'Timer', type: 'widget' });
return true;

Refer to Creating a Client Script help page for more details. 

Try It Out!

A complete working code sample of this widget is attached to this post.

Now, let us see how this Timer widget works:

1. Start the Timer 

Open the widget and select an active case from the dropdown. As soon as you start the timer, a new record will be automatically created in the Timer Entries module to capture the session.

2. Stop the Timer 

When the task is complete, provide a description of the work you have done and stop the timer. The same Timer Entry record (created when the timer was started) will be updated automatically with the end time and your work description.

This forms the foundation for accurate time tracking at the record level. 

In Part 2, we will show how to:

-> Use a workflow and Deluge function to transfer these entries into the Work Log subform inside the relevant Cases record.
-> Use CRM Reports to slice and dice work time for better SLA and productivity insights.

In the meantime, would you like us to address any of your pain-points or have a topic to discuss? Let us know in the comments or reach out to us via support@zohocrm.com.

Until next time, Happy Coding! 

-----------------------------------------------------------------------------------------------------------------

Related Reading

-----------------------------------------------------------------------------------------------------------------

Idea
Previous Kaizen: Client Script Support for Subforms | Kaizen Collection: Directory


    • Recent Topics

    • Automatically creating a ticket in Zoho Desk when an invoice is created in Zoho Books

      I need to find a way to create a ticket automatically (i.e. using workflow) in Zoho Desk whenever an invoice is created in Zoho Books. Please advise if there is a way of doing that?
    • Been getting this error, every now and then "Get count limit exceeded, please try again after 3 mins"

      it is really annoying.
    • Co-existing with Google Workspace

      We currently use GWS and due to legacy practices, we cannot migrate away from it. Not easily anyway. The issue we have is that while we have Zoho Mail, we get duplicate copies of emails. Our setup is that GWS is our primary. We have Zoho MX records in
    • Stop Zoho Projects From Automatically Adding Client Users

      I have a custom function that creates a Zoho Project for every Quote attached to a Deal when it moves to Closed Won. Everything works fine, except for the fact that connecting a Zoho Project to the CRM automatically takes the Contact associated with the
    • dd Linked Note to Comments & History via Custom Function + Zoho Document View Feature

      Hi all, I have a couple of custom functions running in Zoho (specifically in Inventory/Books), and I'm trying to streamline it. Here’s the scenario: When a Purchase Receive is processed, my custom function automatically creates a Package. I'd like to
    • How to break line in zohoCRM

      Hello everyone, I'm currently working with Deluge scripting language and encountering an issue with newline characters (\n). My goal is to format a string with multiple lines, but the newline characters are not being interpreted correctly. Instead of
    • Marketer’s Space: Supercharged Workflow with Zoho CRM Integration

      Hello Marketers! Welcome back to another post in Marketer’s Space. Today, we’ll explore how integrating Zoho CRM with Zoho Campaigns can help you create smarter, more personalized Workflow. In this post, we’ll look at a specific use case to demonstrate
    • Zoho Live chat doesnt chat on CRM Contact page????

      We have used Salesforce Live Agent for the last 8 years and the chat comes in on the Contact record which is logical and intuitive as the chat agent can see the customers sales history and open opportunities...etc... We just migrated to Zoho CRM and I
    • Image Quality Issue on Zoho Assist

      Hello, For the past two days, I've been experiencing a significant image quality issue on Zoho Assist when connecting to one of my computers. I’ve tried reinstalling the application, but the issue persists across multiple devices. The internet connection
    • New views to manage activities within a record

      Dear customers, We hope you're well! Today, we're here with a useful update to the Activities related list. As you might be aware, parent records display related information from other modules as related lists. This helps you get a 360-degree view of
    • Sent Mail not in "Sent" IMAP folder

      I have configured ZOHO to use IMAP. When I send an email from within Zoho, the email does not show up in my "Sent" IMAP folder. Every email client I have ever used, stores sent mails in the "Sent" folder. This is a serious flaw!  Please fix this ASAP! Oliver
    • Add additional field to quick search results

      IN the advanced search, we can add any field to the columns. In the regular search results (before you press enter, there is no option to modify the results. It would be super useful to include a custom field where it currently displays the pipleine
    • Admin Control for Subscribing Users to Bots in Zoho Cliq

      Hello, I would like to request an enhancement to Zoho Cliq, specifically related to subscribing users to bots. Current Issue: When using the Zoho Desk integration with Cliq, notifications such as Mentions, Happiness Ratings, and Pending Blueprint Transitions
    • Eighth Insight - Oversee module relationships with Lookups

      The Wheels of Ticketing - Desk Stories Oversee module relationships with Lookups ‌Learning about lookups A lookup field provides a powerful way to display and utilize data from another module directly within a field of your current module. This functionality
    • New capabilities for custom buttons: Elevate UX and CX with just a click!

      -------------------------------------------------Post moderated on 24th May-------------------------------------------------------------- Dear all, The feature is now available for all users in all DCs. Dear Customers, We hope you're well! We're happy
    • Client Side Scripts for Meetings Module

      Will zoho please add client side scripting support to the meetings module? Our workflow requires most meeting details have a specific format to work with other software we have. So we rely on a custom function to auto fill certain things. We currently
    • CRM APP

      So the crm can now have image uploads. Great for us doing site surveys and linking them to customers. Unfortunatley the crm app does not show the image fields.  Any ideas of must we create a form and then link that?
    • Zia Summary for Account - What is its reach

      Hello! I've been working with the Zia summary feature and it's very useful. However, it seems to pull in notes and things directly "on" the Account. If I have a meeting or phone call and provided detailed summaries with the event associated to the account,
    • Search a custom module record based on a date range

      Hi , I hope you can share some guidance. I need to look up a record from a custom module based on the Closing Date of a Deal (in the Deals module). Here’s the context: 1. I have a custom module that stores quarterly values (e.g., rates or thresholds).
    • How do I associate an expense to multiple projects?

      How do I associate itemized expenses to multiple projects, like assigning each line to the respective project
    • So what's the limit?

      Recently our team encountered an error popping out when sending a service report. Although the report was sent successfully to zoho desk but the site asset record isn't updated. We notice this error occur only when line items [subform record] exceeds
    • Charge to add client users to a ZOHO Project?

      Is there a charge to add client users to access a zoho project portal?  An additional license charge or any other additional costs?  Thank You
    • Zoho CRM Notifications API - Channel Expiry

      Has anyone built a reliable integration with CRM Notification API (https://www.zoho.com/crm/developer/docs/api/v8/notifications/overview.html)? Need to sync CRM data with my external system and prefer not to use CRM workflows which ist a nice low code
    • Create Tasks in arbitrary Zoho Project triggered from CRM [Zoho CRM]

      Community, hello What I'm trying to do is to create a Zoho Project when a Deal is created in CRM and then to be able to add tasks to this Project also from Zoho CRM with the trigger (Blueprint/ Workflow). I succeeded in creating Project using Zoho Flow,
    • job opening status is locked and and I cannot change it

      Dear Support I am using standard plan. The job opening status is locked and and I cannot change it.
    • IDN domain

      Why I can't use my domain www.blažek.com I do not want use unfolded shape www.xn--blaek-wib.com in my mail. Can you help me please?
    • Gmail - Error 553 Relaying Disallowed

      Hey Zoho, I have just set up my mail server and added a couple of email accounts. I've verified my domain and added the mx records with my registrar (namecheap.com) What I'm trying to do is to be able to send email from my domain through Gmail.  In Google
    • Candidate status change

      I am trying to change candidate status from "interview scheduled" to "hired". Where do I do this at?
    • How can I set up my contacts so that all users can have them on hand when they sign in?

      Hi.  For my business I would like to set up the Contacts so they are available for any user. 
    • Sharing Knowledge Base articles across multiple departments

      It would be useful to share some Knowledge Base articles across multiple departments where they are applicable, rather than having to go into other departments to find the article you're looking for. For example. Our reception uses the 'Admin' desk whereas our IT guys use the 'Support' desk, however both divisions would find KB articles about our company intranet useful. Reception does not have access to the support desk, so cannot see articles created in the Support KB. Perhaps you could install
    • Getting Project Template List using the REST API

      I am trying to confirm that I can use the REST API to create a project using a project template. The API documentation indicates this is possible by providing the Template ID, but it is not clear at all how to get a list of available Project Templates
    • Where do we manage tags?

      Where is the page where we can view all tags and manage them (like change a tag name to something else or merge tickets under a particular tag with another)?
    • Custom Return Path - Host Name

      Hi there, I've successfully set up SPF/ DKIM for Marketing Automation, but struggling to complete the Custom Return Path. I'm settting up on Wix. What should the host name be for the CNAME record? In Zoho Help it just says: "type your host name (sub-domain
    • Trouble Connecting Zoho Mail via IMAP in n8n – Need Help

      Hi everyone 👋, I'm trying to connect my Zoho Mail account to n8n using the IMAP Email Trigger node, but I'm facing issues getting it to work fully. ✅ Here's what I’ve done so far: ✅ IMAP access is enabled in my Zoho Mail settings ✅ I’m using the correct
    • How to send Messages to Leads/customers

      I’d like to inquire about the process for sending messages or follow-up communications to customers directly from Zoho CRM. Could you please guide me on the best way to do this—whether via email, SMS, or any integrated messaging feature? Additionally,
    • Daily-rate for projects

      I am billing my client through daily billing rates; for Zoho Books projects, only hourly rates can be set up. Please enhance this. Thanks.
    • AI feature in Zoho Desk suggesting answers based on past ticket threads

      Hi I would like to suggest something that would be very useful : instead of suggesting answers based on the Knowledge Base, I think it would be great if Zia could analyze the history of all customer and agents threads, to suggest answers in new tickets.
    • Admin Console Email

      I can't remember the admin console email or password. How do I find that out?
    • help me! the button "remove zoho ad" is not responding

      help me! the button "remove zoho ad" is not responding, kindly advice. please to check the follows : https://sitepreview-643549202.zohositescontent.com/previewsite https://sitebuilder-643549202.zohositescontent.com/builder thanks,best  regards
    • Zoho Forms API

      Is there any way to get all form entry list using API? Looking forward to hear from you
    • Next Page