- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2023 05:50 PM
Hi guys,
I did a datediff and I need to SUM the result, I tried the code below but is not working.
Could someone help me?
var incidentGA = new GlideAggregate('incident');
incidentGA.query();
while (incidentGA.next()) {
var date1 = new GlideDateTime(incidentGA.sys_created_on);
var date2 = new GlideDateTime(incidentGA.resolved_at);
diff = GlideDate.subtract(date1, date2);
var total = incidentGA.addAggregate('SUM', diff);
gs.info(diff.getDisplayValue());
gs.info(total);
}
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2023 07:21 PM - edited 04-30-2023 07:22 PM
Hi @MR Carvalho ,
As far as I can relate to the question you want to calculate the sum of differences in "TOTAL" variable.
Here I have tried this code, and its working fine.
var total=new GlideDateTime();
total.subtract(total.getNumericValue()); //sets time to zero
gs.print(total);
var incidentGA = new GlideAggregate('incident');
incidentGA.query();
while (incidentGA.next()) {
var date1 = new GlideDateTime(incidentGA.sys_created_on);
var date2 = new GlideDateTime(incidentGA.resolved_at);
diff = GlideDate.subtract(date1, date2);
total.add(diff);
}
gs.print(total);
Let me know if anything more is there to this.
Regards,
Rishabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2023 07:21 PM - edited 04-30-2023 07:22 PM
Hi @MR Carvalho ,
As far as I can relate to the question you want to calculate the sum of differences in "TOTAL" variable.
Here I have tried this code, and its working fine.
var total=new GlideDateTime();
total.subtract(total.getNumericValue()); //sets time to zero
gs.print(total);
var incidentGA = new GlideAggregate('incident');
incidentGA.query();
while (incidentGA.next()) {
var date1 = new GlideDateTime(incidentGA.sys_created_on);
var date2 = new GlideDateTime(incidentGA.resolved_at);
diff = GlideDate.subtract(date1, date2);
total.add(diff);
}
gs.print(total);
Let me know if anything more is there to this.
Regards,
Rishabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2023 01:10 PM
@rishabh katari1 thank you very much.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 04:26 PM