Request Duration

a_e_mcdonald
Tera Expert

I want to use a calculated field in the Dictionary Entry. This scripts returns the wrong values. Is anyone experienced with this?

 

(function calculatedFieldValue(current) {

var duration = gs.dateDiff(current.startTime.getDisplayValue(),current.endTime.getDisplayValue());
current.u_request_duration.setValue(duration);
return 'duration'; // return the calculated value

})(current);

1 ACCEPTED SOLUTION

Michael Fry1
Kilo Patron

Out of the box there is a duration field available at the task level. There are some other fields too like business duration. On a requested item those fields aren't being populated (on other tables they are) but you could copy the out of box business rule named mark_closed on problem table, update the condition and use that to set the out of box fields. Seems like that would be easier and more consistent with how other tables are calculating the values.

View solution in original post

3 REPLIES 3

Michael Fry1
Kilo Patron

Out of the box there is a duration field available at the task level. There are some other fields too like business duration. On a requested item those fields aren't being populated (on other tables they are) but you could copy the out of box business rule named mark_closed on problem table, update the condition and use that to set the out of box fields. Seems like that would be easier and more consistent with how other tables are calculating the values.

Chuck Tomasi
Tera Patron

There's two things that jump out at me on the script. One is your are returning a 'duration' string, not the value. If you are using a calculated value, it's only calculated when the record is updated, not dynamically.

The second thing is you are doing a current.field.setValue() within the calculated value, that's not needed since the calculated field is doing that same thing. You are using it more like a BEFORE business rule. Try this instead (assuming your field is a duration field)

(function calculatedFieldValue(current) {

  var duration = 
  gs.dateDiff(current.startTime.getDisplayValue(),current.endTime.getDisplayValue());

  return duration; // return the calculated value

})(current);

I thought the same thing. However if I remove either:

current.u_request_duration.setValue(duration);

or


return 'duration'; // return the calculated value

 

the fields will not populate without both lines of code being there.