In case you are using the [time_worked] field on some tasks in ServiceNow you might have experienced already the behavior that it is counting and counting and counting whenever an incident or any other task is open.
This behavior is the out-of-the-box behavior but not always wanted. In case you want to report on that time regularly and people are still having the task open if it is resolved or closed you might not get the picture you would expect.
Yes…. you are reading right. The [time_worked] counter counts also if the task is already resolved, completed, closed, or canceled, and if you use the out-of-the-box property the counter starts onLoad.
But there is a solution to this. You just have to add a client script to the task table or to whatever table you want to stop the counter for these statuses. Or in case you train your people to start the counter manually you can of course disable the property [glide.ui.timer.started]
Client script to stop the [time_worked] counter
Below client script will stop the counter and disable the button next to the counter until the state is changed and the task is saved. This script is designed on the task level and has some common ITSM process statuses that it checks for. You can adjust/extend the script to your own needs.
To have it working properly make sure to disable the “Isolate” checkbox.
Make sure to test the script in a development environment before deploying it to production!
function onLoad() { //Type appropriate comment here, and begin script below var status = g_form.getValue('state'); if(g_form.getElement('time_worked') && ['3','4','6','7','8','106','107','157'].indexOf(status) >= 0){ toggleTimer('time_worked','00:00:00'); g_form.setReadOnly('time_worked', true); } } function toggleTimer(fieldName,timerVal){ try{ //Get the necessary timer elements for fieldName given var timerEl = $('element.' + g_form.tableName + '.' + fieldName); var timerIcon = $('link.' + g_form.tableName + '.' + fieldName); if (timerEl != null){ //Make sure script does not break if field not present var timerPause = timerEl.select('input[id*=paused]')[0]; //Toggle the timer if(timerPause.value == 'false'){ timerPause.value = 'true'; timerIcon = $('link.' + g_form.tableName + '.' + fieldName); timerIcon.removeClassName('icon-stop'); timerIcon.addClassName('icon-play'); } else{ timerPause.value = 'false'; timerIcon.removeClassName('icon-play'); timerIcon.addClassName('icon-stop'); } //Reset the timer to timerVal given /*if(timerVal){ g_form.setValue(fieldName,timerVal); }*/ } }catch(e){} }
Hi,
Looks like this code does not work in workspace view. Is there any alternate solution available for workspace view.
Regards,
Ajeet
Unfortunately it does not work within a workspace view.
This is not working for agent workspace
Do you have any idea ?
Unfortunately you can’t use that functionality in a workspace because it uses DOM to identify the objects to modify. This is not possible in a workspace and also confirmed by SN support.