Time Tracking on Incident via time_worked field

Javeria
Tera Guru

Hi Devs,

I have a requirement that the Time Worked timer should not auto-start, and I achieved this by setting the following:

glide.ui.timer.started = false

That worked fine.

However, I now have two additional requirements, and I’m not sure whether they are possible:

Make the Time Worked field read-only while still allowing users to interact with only the Start / Pause / Stop timer controls.
I tried using a UI Policy and Client Script, but when the field is made read-only, the timer controls also become hidden/frozen.
Keep the timer running even if the ticket form is closed.

Can anyone confirm whether these requirements are possible in ServiceNow or if there’s any recommended workaround?

 

Regards,

Javeria

2 REPLIES 2

Naveen20
ServiceNow Employee

Try this

1. Read-only field but interactive timer controls:

This is tricky because the Time Worked field (time_worked) is a composite widget — the duration display and the timer buttons are part of the same GlideTimer UI element. When you set it read-only via UI Policy or Client Script (g_form.setReadOnly('time_worked', true)), it locks the entire widget including the controls.

Workaround: Instead of making the field read-only, use a Client Script (onChange) to prevent manual edits to the duration boxes while leaving the timer buttons functional:

// Client Script - onChange on 'time_worked'
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;
    // Revert any manual typing, only allow timer-driven changes
    var timerActive = g_form.getControl('time_worked')
        .querySelector('.icon-play, .icon-pause');
    // Alternative: use DOM manipulation to set the input boxes as readonly
}

A more reliable approach is to use a UI Macro or client-side DOM manipulation to target just the <input> elements inside the timer widget and set them to readonly at the HTML level, while leaving the button icons untouched:

// onLoad Client Script
function onLoad() {
    var timerEl = g_form.getControl('time_worked');
    var inputs = timerEl.parentElement.querySelectorAll('input[type="text"]');
    inputs.forEach(function(inp) {
        inp.setAttribute('readonly', 'readonly');
        inp.style.backgroundColor = '#e9ecef'; // visual cue
    });
}

This keeps the start/pause/stop buttons clickable while preventing users from typing values directly. Note: this is a DOM-level approach, so test across form views and after upgrades.

2. Keep timer running after form is closed:

Not possible out-of-box. The GlideTimer is a client-side JavaScript timer — it only runs while the form is open in the browser. Once you navigate away or close the tab, the timer stops and only the accumulated value up to that point is saved.

Workarounds:

  • Server-side time tracking: Use a Business Rule to stamp a u_timer_start date/time field when the user clicks start, then calculate elapsed time on form load or on stop. This makes time tracking independent of the browser session.
  • SLA-based approach: Use a Task SLA definition that tracks time worked based on state/assignment changes rather than a manual timer, which inherently survives form closures.

The server-side timestamp approach is the most common pattern teams use to get persistent timing behavior.

Tanushree Maiti
Kilo Patron

Use UI policy only to achieve your requirement : Make the Time Worked field read-only

 

1. Screenshot 2026-04-09 144246.png

 

Record level

 

Screenshot 2026-04-09 144202.png

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: