The CreatorCon Call for Content is officially open! Get started here.

Count Incident

Mushir
Giga Guru

write a background script for count incident which SLA has been breached

5 ACCEPTED SOLUTIONS

Bhavya11
Kilo Patron
Kilo Patron

Hi @Mushir ,

 

you can try below code to get the count 

var slaBreached =0;
var slaGr = new GlideAggregate("task_sla");
slaGr.addQuery("task.sys_class_name=incident^has_breached=true");
slaGr.addAggregate("COUNT");
slaGr.query();
while(slaGr.next()){
	slaBreached=slaGr.getAggregate("COUNT");
}
gs.print("Count incident which SLA has been breached "+slaBreached);

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Thanks,

BK

 

View solution in original post

Runjay Patel
Giga Sage

Hi @Mushir ,

 

You can use below script.

var slaBreached = 0;
var slaGr = new GlideAggregate("task_sla");

// Query for breached SLAs related to incidents
slaGr.addQuery("task.sys_class_name", "incident");
slaGr.addQuery("has_breached", true);
slaGr.addAggregate("COUNT");
slaGr.query();

// Fetch the count directly without looping
if (slaGr.next()) {
    slaBreached = slaGr.getAggregate("COUNT");
}

// Print the result
gs.print("Count of incidents with breached SLAs: " + slaBreached);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...

Hi Bhavya 

can you explain me sys_class_name  field where i can find it in my PDI

View solution in original post

Hi Runjay

can you explain me  about sys_class_name  field where i can find it in my PDI

View solution in original post

Hi @Mushir ,

 

Table Inheritance: ServiceNow uses a system where tables are organized in a hierarchy, with child tables inheriting from parent tables. The sys_class_name field shows which table or class a record belongs to. For example, a record in the incident table will have a sys_class_name of “incident,” but if the record is part of a different class, like “problem,” it will show that class name instead.

If my response helped, please mark it as the accepted solution and give a thumbs up👍.
Thanks,
Anand

View solution in original post

9 REPLIES 9

Bhavya11
Kilo Patron
Kilo Patron

Hi @Mushir ,

 

you can try below code to get the count 

var slaBreached =0;
var slaGr = new GlideAggregate("task_sla");
slaGr.addQuery("task.sys_class_name=incident^has_breached=true");
slaGr.addAggregate("COUNT");
slaGr.query();
while(slaGr.next()){
	slaBreached=slaGr.getAggregate("COUNT");
}
gs.print("Count incident which SLA has been breached "+slaBreached);

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Thanks,

BK

 

Hi Bhavya 

can you explain me sys_class_name  field where i can find it in my PDI

Runjay Patel
Giga Sage

Hi @Mushir ,

 

You can use below script.

var slaBreached = 0;
var slaGr = new GlideAggregate("task_sla");

// Query for breached SLAs related to incidents
slaGr.addQuery("task.sys_class_name", "incident");
slaGr.addQuery("has_breached", true);
slaGr.addAggregate("COUNT");
slaGr.query();

// Fetch the count directly without looping
if (slaGr.next()) {
    slaBreached = slaGr.getAggregate("COUNT");
}

// Print the result
gs.print("Count of incidents with breached SLAs: " + slaBreached);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...

Hi Runjay

can you explain me  about sys_class_name  field where i can find it in my PDI