Reporting how many Incidents are linked to an Change Request

chrifan
Mega Expert

Hi,

I'm want to how many Incidents triggered a Change Request and how many Incidents were triggered by a failed Change. How to build a suitable filter for this purpose? Thx

2 ACCEPTED SOLUTIONS

AndersBGS
Tera Patron

Hi @chrifan ,

 

For "incidents triggered a change request" you can create a report based on the incident table with the condition:

AndersBGS_0-1700033836210.png

 

For "incidents were triggered by a failed change" you can create a report based on the incident table with the condition:

AndersBGS_1-1700033893037.png

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

 

 

View solution in original post

Amit Gujarathi
Giga Sage

HI @chrifan ,
I trust you are doing great.
Please find the below code 

// Get the current Change Request record
var changeRequest = new GlideRecord('change_request');
if (changeRequest.get(current.change_request)) {
    // Count Incidents linked to this Change Request
    var incidentCount = new GlideAggregate('incident');
    incidentCount.addQuery('related_to', current.change_request);
    incidentCount.addAggregate('COUNT');
    incidentCount.query();

    if (incidentCount.next()) {
        // Display the count on the Change Request form
        current.incidents_linked = incidentCount.getAggregate('COUNT');
    }

    // Count Incidents triggered by this Change Request and marked as Failed
    var failedIncidentCount = new GlideAggregate('incident');
    failedIncidentCount.addQuery('triggered_by', current.change_request);
    failedIncidentCount.addQuery('state', 'Failed'); // Assuming the state field indicates failure
    failedIncidentCount.addAggregate('COUNT');
    failedIncidentCount.query();

    if (failedIncidentCount.next()) {
        // Display the count on the Change Request form
        current.failed_incidents = failedIncidentCount.getAggregate('COUNT');
    }
}

View solution in original post

7 REPLIES 7

chrifan
Mega Expert

Thanks to you both,

@AndersBGS this was the direct way I wanted to, indeed. Thank you.

But  the code snippet by @Amit Gujarathi could be helpful for the DevOps too.

Dr Atul - LNG
Tera Patron

Hi @chrifan 

 

Greetings!!

 

As a best practice, avoid script if possible. The solution is already provided by @AndersBGS 

 

Hi @Dr Atul - LNG 

Greetings !!

Thanks for the hint.
I regard your code snippet as a backup solution, exit code, last man standing, ...
I appreciate best pratice, I do.

Very best regards
Chris F.