How to find incidents attached to the problem records?

Ramanjaneyuv
Tera Contributor

How to find incidents  attached to the problem records?

Scenario: we have 10 problem records , out of 4 problem records have incidents  ,how to achieve this ?

Please help me on this.

Thanks

1 ACCEPTED SOLUTION

Harish Bainsla
Tera Sage
Tera Sage

Hi @Ramanjaneyuv  check below script 

var grProblem = new GlideRecord('problem');
grProblem.query();

while (grProblem.next()) {
 
var problemNumber = grProblem.getValue('number');
 
var grIncident = new GlideRecord('incident');
grIncident.addQuery('problem_id', grProblem.sys_id);
grIncident.query();
 
gs.print('Problem Record: ' + problemNumber);

if (grIncident.hasNext()) {
gs.print('Related Incidents:');
 
while (grIncident.next()) {
 
gs.print(' - Incident Number: ' + grIncident.getValue('number'));
}
} else {
gs.print('No related incidents.');
}
}
Screenshot 2024-06-10 at 9.21.50 AM.png

View solution in original post

5 REPLIES 5

Harish Bainsla
Tera Sage
Tera Sage

Hi @Ramanjaneyuv if my answer helps you please accept solution and mark helpful