How to add multiple duration fields and populate the result on another duration field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 10:27 AM
Hi,
I have the table u_impact_services which has the field u_total_dur of type Duration.
I need to write Business Rule on the incident table that will glide record u_impact_services table and add the field u_total_dur from multiple record and then populate the answer in a Duration field on the incident table
How can I achieve that? I tried this but its not working
(function executeRule(current, previous /*null when async*/) {
var totalDuration = new GlideDuration(); // Initialize a GlideDuration object
var gr = new GlideRecord('u_impact_services');
gr.addEncodedQuery('u_incident.ref_incident.problem_id=' + current.sys_id + '^u_impact_total_durISNOTEMPTY');
gr.query();
while (gr.next()) {
var impactDuration = new GlideDuration(gr.u_impact_total_dur);
totalDuration.add(impactDuration);
}
current.u_total_impact_duration = totalDuration.getDurationValue();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 10:35 AM
@Alon Grod Can you try this in background script at every juncture and try to log if you are getting possible values.
(function executeRule(current, previous /*null when async*/) {
// Initialize a GlideDuration object to store the total duration
var totalDuration = new GlideDuration(0); // Start with 0 milliseconds
// Query the u_impact_services table
var gr = new GlideRecord('u_impact_services');
gr.addEncodedQuery('u_incident=' + current.sys_id + '^u_total_durISNOTEMPTY'); // Adjust the query as needed
gr.query();
// Loop through the records and sum the u_total_dur field
while (gr.next()) {
var impactDuration = new GlideDuration(gr.getValue('u_total_dur')); // Get the duration value
totalDuration.add(impactDuration); // Add to the total duration
}
// Set the total duration on the incident record
current.u_total_impact_duration = totalDuration; // Assign the GlideDuration object directly
})(current, previous);
Thanks,
Mahesh.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2025 10:41 AM
I think a GlideAggregate will sum a GlideDuration field. If not you can use this
And then add everything up.