Modify time_worked field when state changes

shane_davis
Tera Expert

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.

find_real_file.png

Thank you for your help in advance!

2 REPLIES 2

ghsrikanth
Tera Guru

Could you please post the new business rule script, may be some one in community can help you with


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



find_real_file.png



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();


  }