Work Order Task: Break Time Field Not Summing Duration from Time Worked Records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 09:48 PM
On the Work Order table, there's a "Break Time" field with the "Duration" type set to "Read Only." This field should automatically accumulate the total break time from related "Time Worked" records where the category is "Break." The script is implemented, but the accumulation isn't working as expected.
As shown in the image below, there are two break times: the first with a duration of 10 hours and the second with a duration of 2 hours. However, the "Break Time" field only shows 2 hours instead of the expected 12 hours.
Form
My Business Rules Script
var totalBreakDuration = 0;
// Query time worked yang terkait dengan task dan kategori "break"
var timeWorkedGr = new GlideRecord('task_time_worked');
timeWorkedGr.addQuery('task', current.sys_id);
timeWorkedGr.addQuery('category', 'break');
timeWorkedGr.query();
while (timeWorkedGr.next()) {
totalBreakDuration += timeWorkedGr.time_worked.getGlideObject().getDurationValue(); // Jumlahkan durasi
}
// Update field pada Work Order Task dengan total durasi break
current.u_break_time = totalBreakDuration;
current.update();
gs.print(totalBreakDuration.getDisplayValueinternal());
})(current, previous);