CLIENT WANT TO TOTAL P1 TICKETS RECORDS DATA, HOW CAN I WRITE THE SCRIPT FOR THIS BUSSINESS RULE.

Neerudus
Tera Contributor
 
2 ACCEPTED SOLUTIONS

Shraddha Kadam
Mega Sage

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("--------------------------------------");
If my response was helpful, please mark it as correct and helpful.
Thank you.

View solution in original post

Sujit Jadhav
Tera Guru

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




View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

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]

****************************************************************************************************************

Shraddha Kadam
Mega Sage

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("--------------------------------------");
If my response was helpful, please mark it as correct and helpful.
Thank you.

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]

****************************************************************************************************************

Sujit Jadhav
Tera Guru

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