How do I "Stop" Time Worked when task is closed?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2009 03:51 PM
I'm trying to pause the timer when the task is closed, but an itil user is going back to key additional information (SLMs love doing this).
This is starting to skew our time tracking. Just wondering if somebody knows how to stop the timer using a client script? (Simulate an onClick event?)
I've found "Toggle Timer Field by Field Name":
http://wiki.service-now.com/index.php?title=Toggle_Timer_Field_by_Field_Name
I know I can also update the business rule
Incident Time Workedto drop the update based on incident state, but I'm looking for a solution that is visible to the user.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2009 04:25 PM
The wiki article you've referenced is exactly what you need I think. Is it not working for you?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2009 04:27 PM
One other thought: the timer can't start if it's not on the form. You could create a separate view for closed incidents and then force the view using view rules. I'm not sure if it's worth it to you to have the overhead of another view just for this purpose, but that should work too. The only problem with a client script solution is that you usually end up with a minor delay (1-3 seconds in my experience) before the timer actually gets paused.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2009 04:33 PM
Here's the 'onLoad' script I've used before to pause the timer. It resets the timer after it gets paused so you always end up with zeroes if the timer is paused (which eliminates the delay issue).
function onLoad() {
toggleTimerByFieldName("incident.time_worked");
g_form.setValue("time_worked","00:00:00");
}
function toggleTimerByFieldName(fieldName) {
//Step 1: Find the timer object
//timeObjectName: the timer objects name as it would normally be referenced
//timeObjectHidden: the hidden input node in the field td
//timeObjectParent: the parent td node containing the field and it's constituent nodes
//timeObjectFields: anchor tag with onclick to stop timer
var timeObjectName = fieldName;
var timeObjectHidden = gel(timeObjectName);
//Step 2: simulate click on stop button
var timeObjectParent;
var timeObjectFields;
//verify that we got the correct object
if (timeObjectHidden.type == "hidden") {
//Get Parent td node
timeObjectParent = timeObjectHidden.parentNode;
//Get input fields
timeObjectFields = timeObjectParent.getElementsByTagName("input");
//simulate click of stop button
var timerTestString = "paused";
var timerImg;
//loop through input objects looking for the pause timer object
for(var elIt=0;elIt<timeObjectFields.length;elIt++) {
if (timeObjectFields[elIt].id.match(timerTestString)) {
if(timeObjectFields[elIt].value == "false") {
timeObjectFields[elIt].value = "true";
timerImg = timeObjectParent.getElementsByTagName("img")[0];
timerImg.src = "images/timer_start.gifx";
} else if (timeObjectFields[elIt].value == "true") {
timeObjectFields[elIt].value = "false";
timerImg = timeObjectParent.getElementsByTagName("img")[0];
timerImg.src = "images/timer_stop.gifx";
}
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2009 07:39 PM
Thanks Mark it's working beautifully now mate.
I guess my interpretation of the function name was making me think it was for something else. I thought "toggle" was setting the field visibility on and off, but it's actually toggling the pause state.
Thanks for the point on setValue() of the timer field. Makes the solution work just as I'd hoped.
I like this way over hiding the field entirely. It allows SLMs to go in and "mark up" time worked if appropriate, but doesn't interfere with the time worked if they're just doing data corrections etc.
Cheers 🙂