- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2019 05:16 AM
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);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2019 06:34 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2019 06:34 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2019 06:35 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2019 09:29 AM
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.