Write a script to show incident count for each state which are updated today?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 05:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 09:20 AM
Let me know if this work to you
(function() {
// Get today's date at midnight (00:00:00)
var today = new GlideDateTime();
today.setDisplayValue(gs.nowDate() + ' 00:00:00');
// Query incident table for incidents updated today
var incGR = new GlideAggregate('incident');
incGR.addEncodedQuery('sys_updated_on>=javascript:gs.beginningOfToday()');
incGR.groupBy('state');
incGR.addAggregate('COUNT');
incGR.query();
// Output the result
while (incGR.next()) {
var state = incGR.getDisplayValue('state'); // Get readable state name
var count = incGR.getAggregate('COUNT');
gs.print('State: ' + state + ' | Count: ' + count);
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 09:34 AM
Hi @HARSHITS3436786 ,
You can use the below script:
var incGR = new GlideAggregate('incident');
incGR.addEncodedQuery('sys_updated_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()'); // You can add more conditions in this EncodedQuery
incGR.addAggregate('COUNT');
incGR.groupBy('state');
incGR.query();
while (incGR.next()) {
gs.print(incGR.getDisplayValue('state') + " -> " + incGR.getAggregate('COUNT'));
}
If this solution helps you then, mark it as accepted solution ✔️ and give thumbs up👍!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 09:41 AM - edited 08-01-2025 09:42 AM
Hello @HARSHITS3436786 ,
Please find the script with example, kindly refer the SS-
var gr = new GlideAggregate('incident');
gr.addEncodedQuery("sys_updated_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");
gr.groupBy('incident_state');
gr.addAggregate('COUNT');
gr.query();
gs.print("Incident count by state updated today:--");
while (gr.next()) {
var state = gr.getDisplayValue('incident_state');
var count = gr.getAggregate('COUNT');
gs.print(state + ": "+count);
Thanks,
Bhanu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2025 03:28 PM
what is the business value to show by each state? An incident updated today can be for changing the state 10 times, changing a category or something third - so what is it from a business perspective you will achieve by doing this?
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/