I want to send email for only 20% of incidents with close/resolved how can i achieve this?

RMU
Tera Contributor

I want to send email for only 20% of incidents with close/resolved how can i achieve this?

1 ACCEPTED SOLUTION

Hi @RMU 

 

Thanks for confirmation...!!

 

Not sure if this business requirement....but assuming you are writing scheduled job to send the email.

Following script might help...!!

 

 

/*1. Glide Record on incident table & get row count */
var grInc = new GlideRecord("incident");
grInc.addEncodedQuery('stateIN6,7');
grInc.query();

/*2. Here we will get the totla number of incident */
var totalInc = grInc.getRowCount();
gs.print("Total incident count = " + totalInc);

/*3. Calulate 20% of totalInc */
var percentage = 20;
var number = (percentage/100) * totalInc;
gs.print("20% of totalInc = " + number);

/*4. Need to Glide record on Incident table again to limit the recors with  "20% of totalInc" */
var gr = new GlideRecord("incident");
gr.addEncodedQuery('stateIN6,7');
gr.setLimit(number);
gr.query();
while(gr.next()){
 gs.print(gr.number);
 // gs.eventQueue('ebent_name',gr,gr.caller); 
}

 

 

VishalBirajdar_0-1697693589210.png

 

This logic will get the 20% random incident from total incident

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

4 REPLIES 4

Danish Bhairag2
Tera Sage
Tera Sage

Hi @RMU ,

 

You can just use addEncodedQuery() in ur glide record & copy paste the query into it. Go to ur list view select those 20% incidents manually by applying filter , run that filter copy the query from the filter by right clicking on it & paste it in ur encoded query.

In that GlideRecord u can call event & trigger the notification.

Ur notification trigger point should be when event fired.

 

Thanks,

Danish

 

Vishal Birajdar
Giga Sage

Hi @RMU 

 

20% in the sense , if there are 100 incidents with closed/resolved then send email to only 20 ??

Is my understanding is correct...??

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Yeah , exactly

 

Hi @RMU 

 

Thanks for confirmation...!!

 

Not sure if this business requirement....but assuming you are writing scheduled job to send the email.

Following script might help...!!

 

 

/*1. Glide Record on incident table & get row count */
var grInc = new GlideRecord("incident");
grInc.addEncodedQuery('stateIN6,7');
grInc.query();

/*2. Here we will get the totla number of incident */
var totalInc = grInc.getRowCount();
gs.print("Total incident count = " + totalInc);

/*3. Calulate 20% of totalInc */
var percentage = 20;
var number = (percentage/100) * totalInc;
gs.print("20% of totalInc = " + number);

/*4. Need to Glide record on Incident table again to limit the recors with  "20% of totalInc" */
var gr = new GlideRecord("incident");
gr.addEncodedQuery('stateIN6,7');
gr.setLimit(number);
gr.query();
while(gr.next()){
 gs.print(gr.number);
 // gs.eventQueue('ebent_name',gr,gr.caller); 
}

 

 

VishalBirajdar_0-1697693589210.png

 

This logic will get the 20% random incident from total incident

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates