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
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

 

 

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

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

View solution in original post

Amit Gujarathi
Giga Sage
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');
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

7 REPLIES 7

AndersBGS
Tera Patron
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

 

 

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

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Amit Gujarathi
Giga Sage
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');
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi @Amit Gujarathi ,

 

Why on earth are you posting a script when he is asking for OOTB filter condition? There is no need to script when you can utilize OOTB functionality.

 

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

 

best regards

Anders

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

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Hi @AndersBGS , My bad I just missed the filter ask in the query.
@chrifan Please refer the filter condition by Anders


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi