- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 08:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 08:09 AM
Hello @Neerudus ,
Please use the below script to get the priority 1 records data for Incident table (You can mention your table in the GlideRecord) -
var p1IncidentCount = 0;
// Create a new GlideRecord object for the 'incident' table
var gr = new GlideRecord('incident');
gr.addQuery('priority', '1');
// Execute the query
gr.query();
// Loop through the query results
while (gr.next()) {
p1IncidentCount++; // Increment the counter for each P1 incident found
// Print the incident number and short description
// You can add more fields here if needed (e.g., gr.assigned_to.getDisplayValue())
gs.print("Incident Number: " + gr.number + ", Short Description: " + gr.short_description);
}
gs.print("--------------------------------------");
gs.print("Total P1 Active Incidents Found: " + p1IncidentCount);
gs.print("--------------------------------------");
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 08:12 AM - edited 07-16-2025 08:13 AM
Hello @Neerudus ,
When to run: before or after (depending on your use case)
(function executeRule(current, gsn) {
// GlideAggregate is used to count records efficiently
var ga = new GlideAggregate('incident');
ga.addQuery('priority', '1'); // Filter for P1 tickets
ga.addAggregate('COUNT');
ga.query();
if (ga.next()) {
var totalP1 = ga.getAggregate('COUNT');
gs.info('Total P1 Tickets: ' + totalP1);
// Optionally, store this value somewhere or trigger another action
// Example: current.u_total_p1_tickets = totalP1;
}
})(current, gsn);
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Sujit Jadhav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 08:06 AM
Hi @Neerudus
What do you mean by total record data, are you Looking for resolve time or else. Plz explain more.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 08:09 AM
Hello @Neerudus ,
Please use the below script to get the priority 1 records data for Incident table (You can mention your table in the GlideRecord) -
var p1IncidentCount = 0;
// Create a new GlideRecord object for the 'incident' table
var gr = new GlideRecord('incident');
gr.addQuery('priority', '1');
// Execute the query
gr.query();
// Loop through the query results
while (gr.next()) {
p1IncidentCount++; // Increment the counter for each P1 incident found
// Print the incident number and short description
// You can add more fields here if needed (e.g., gr.assigned_to.getDisplayValue())
gs.print("Incident Number: " + gr.number + ", Short Description: " + gr.short_description);
}
gs.print("--------------------------------------");
gs.print("Total P1 Active Incidents Found: " + p1IncidentCount);
gs.print("--------------------------------------");
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 08:43 AM
Hi @Neerudus
I'm surprised that you accepted this answer as a solution when your question wasn't even clear. You can create a simple report on the Incident table to get all P1 tickets—no code is required for that.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 08:12 AM - edited 07-16-2025 08:13 AM
Hello @Neerudus ,
When to run: before or after (depending on your use case)
(function executeRule(current, gsn) {
// GlideAggregate is used to count records efficiently
var ga = new GlideAggregate('incident');
ga.addQuery('priority', '1'); // Filter for P1 tickets
ga.addAggregate('COUNT');
ga.query();
if (ga.next()) {
var totalP1 = ga.getAggregate('COUNT');
gs.info('Total P1 Tickets: ' + totalP1);
// Optionally, store this value somewhere or trigger another action
// Example: current.u_total_p1_tickets = totalP1;
}
})(current, gsn);
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Sujit Jadhav