Fetch the problem records which are inactive and having the Incidents in related list with incident related data like number and short description using background script

Divi
Mega Guru

Hi All,

 

I need to fetch the problem records which are inactive and  having the Incidents in related list using background script where i need to display the incident number and short description after execution of the background script.Any help would be appreciated.

Thank you.

1 ACCEPTED SOLUTION

Munender Singh
Mega Sage

var gr = new GlideRecord('problem');
gr.addQuery('state',4);
gr.query();
while(gr.next()){

var gi = new GlideRecord('incident');
gi.addQuery('problem_id',gr.sys_id);
gi.query();
while(gi.next()){
gs.print('Problem -'+gr.number +' Incident - '+gi.number+' Short description - '+gi.short_description);
}
}

 

Try this

 

Regards,

Munender

View solution in original post

4 REPLIES 4

asifnoor
Kilo Patron

Hi Divi,

Try this code. This gives the list of incidents whose problem is inactive and associated with the incident.

var gr = new GlideRecord("incident");
gr.addEncodedQuery("problem_idISNOTEMPTY^problem_id.active=false");
gr.query();
while(gr.next()) {
  gs.print(gr.number);
  gs.print(gr.short_description);
}

Mark the comment as a correct answer and helpful once worked.

Munender Singh
Mega Sage

var gr = new GlideRecord('problem');
gr.addQuery('state',4);
gr.query();
while(gr.next()){

var gi = new GlideRecord('incident');
gi.addQuery('problem_id',gr.sys_id);
gi.query();
while(gi.next()){
gs.print('Problem -'+gr.number +' Incident - '+gi.number+' Short description - '+gi.short_description);
}
}

 

Try this

 

Regards,

Munender

Priyanka136
Mega Guru

Hi Divi,

Please refer the below code:-

var gr = new GlideRecord('problem');
gr.addEncodedQuery('active=false');
gr.query();
gs.print(gr.getRowCount());

var inc = new GlideRecord('incident');
inc.addEncodedQuery('problem_idISNOTEMPTY');
inc.query();
if(inc.next()) 
{
  gs.print(inc.number);
  gs.print(inc.short_description);
}

Please let me know if you have any questions.

Thanks,

Priyanka

Vasishta2
Tera Contributor

var gr = new GlideRecord("problem");
gr.addQuery("active","=","false");
gr.query();

while(gr.next()){
var gr1 = new GlideRecord("incident");
gr1.addQuery("problem_id",gr.sys_id);
gr1.query();

while(gr1.next()){
gs.print("Incident Number: " + gr1.number + "Short Description: " + gr1.short_description);

}

}

Thanks and Regards

Vasishta