Write a script to display inactive problems with p2 incidents.

sabbani rishika
Tera Contributor

Script

12 REPLIES 12

@sabbani rishika 

update as this

var arr = [];
var gr = new GlideRecord('problem');
gr.addQuery("active", false);
gr.addQuery('state',4);
gr.query();
while(gr.next()){
	var r = new GlideRecord('incident');
	r.addQuery("problem_id", gr.sys_id);
	r.addQuery('priority',2);
	r.query();
	while(r.next()){
		arr.push(gr.number.toString());
	}
}

gs.addInfoMessage(arr.toString());

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I've used DISPLAY business rule type.

kunal20
Kilo Guru

Hi Sabbani,

You can use the following script, it will fetch out  the related priority 2 incident for a certain problem.

var arr=[];
var prob=new GlideRecord('problem');
prob.addQuery('active',false)
prob.query();
while(prob.next()){
 var inc=new GlideRecord('incident');
 inc.addQuery('problem_id',prob.sys_id);
 inc.addQuery('priority',2);
 inc.query();
 while(inc.next()){
     arr.push(inc.sys_id+"");
     
 }
    
}