Modify time_worked field when state changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2016 08:26 AM
I have an enhancement to indicate how long a Story [rm_story] has been in its current State and resets to 0 time when the State changes.
From my research, the Time Worked [time_worked] field is on the Task table and uses the business rules "Task Time Worked" and "Update task timer". I always prefer not to modify OOB business rules, but I don't see a way around this. During my trial & error, I inactivated the OOB rule and created a new one but nothing I have tried is working!
So far, I have tried setting filter conditions, setting field values, and also scripting in the business rule.
Thank you for your help in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2016 09:12 AM
Could you please post the new business rule script, may be some one in community can help you with
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2016 09:21 AM
Below is the OOB script but I added lines 4-9 to try to make the timer reset. The highlighted part in the screenshot below is the main part I was having an issue resetting, but if I can get the Hours, Minutes, Seconds sections to work correctly, I will not have to modify the main highlighted counter. My main issue right now is that every time I save, the Hours, Minutes, Seconds revert to 00:00:00; not just when the State changes
function onAfter(current, previous) {
createTimeWorked();
var st = current.state;
function createTimeWorked() {
if (current.state.changes()) {
g_form.setValue('time_worked') == '00:00:00';
}
//updated task, calc difference in timer
if (current.operation() == 'update') {
var end = current.time_worked.dateNumericValue();
var start = previous.time_worked.dateNumericValue();
var diff = end - start;
}
else {
var diff = current.time_worked.dateNumericValue();
}
if (diff == 0)
return;
var tw = new GlideRecord('task_time_worked');
tw.user = gs.userID();
tw.task = current.sys_id;
tw.time_worked.setDateNumericValue(diff);
if (current.comments.changes()) {
tw.comments = current.comments.getJournalEntry(1);
}
tw.insert();
}