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

Arpan Baishya
Kilo Sage

Hi @Ramanjaneyuv,

 

A Problem record has an Incidents related list to show the associated incidents. What is it that you are trying to do? 

Thanks for the your response @Arpan Baishya .  I am getting total count but here my question is Which problem ticket to associate with incident. Please help me on this. I have pasted  my code below.

var gr = new GlideAggregate('problem');
gr.addQuery('related_incidents');
//gr.addQuery('number');
gr.groupBy('related_incidents');
gr.addAggregate('Count');
gr.query();
if(gr.next()){
    var problem1 = gr.getAggregate('Count');
   
    gs.print(problem1);
  
}

Danish Bhairag2
Tera Sage
Tera Sage

Hi @Ramanjaneyuv ,

 

Do u require a script to find this info?

 

If not then as @Arpan Baishya has suggested in the related list there is a tab which shows Problem record info u can utilise that

 

Thanks,

Danish

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