How to get Highest Impact Value of an Incident that are assocaited with Change Number

Murugan Arumuga
Tera Contributor

I have a set of change numbers and multiple incidents with different Impact been tagged to each Change Numbers. I want to get the unique count of incident which has highest impact value. 

 

For Eg.,

The CHG0001234 is associated with below incidents :

INC0001234 >> 4 - Minor / Localized

INC0002234 >> 4 - Minor / Localized

INC0001254 >> 4 - Minor / Localized

INC0001233 >> 5 - No Impact / Single User

INC0001233 >> 3 - Moderate / Limited

INC0002233 >> 3 - Moderate / Limited

 

From the above i want to get highest Impact as  "3 - Moderate / Limited" with distinct Incident count.

I'm using Indicator source and indicators. From the Incident table, i m picking "Causedby Change" as distinct count where i m getting list of change # and incident that were associated to that. I want to report unique count of incident with highest impact that tagget to the CR.

Let me know this can be done with script or relation table.

 

6 REPLIES 6

Community Alums
Not applicable

Hi @Thian Jin1 ,

Please check the below code I fix there is some issue with that now it is fixed 

function calculateIndicator(incGR) {
    var changeNumbers = {}; // Object to store change numbers and their corresponding minimum impact values

    var incidentGr = new GlideRecord('incident'); // Query the Incident table
    incidentGr.addEncodedQuery('caused_by=c83c5e5347c12200e0ef563dbb9a7190'); // Only active incidents
    incidentGr.query();

    // Loop through the incidents
    while (incidentGr.next()) {
		gs.print("inside while");
        var changeNumber = incidentGr.getValue('caused_by');
        var impact = parseInt(incidentGr.getValue('impact')); // Assuming 'impact' is a numeric field
		gs.print("changeNumber = " + changeNumber + " impact = " + impact);

        if (!changeNumbers[changeNumber] || impact < changeNumbers[changeNumber]) {
			gs.print("inside If");
            changeNumbers[changeNumber] = impact;
        }
    }

    // Find the change numbers with the lowest impact value of 2
    var lowestImpactChangeNumbers = [];
    for (var cn in changeNumbers) {
		gs.print("inside For " + changeNumbers[cn]);

        if (changeNumbers[cn] == 3) {
			gs.print("inside For If");
            lowestImpactChangeNumbers.push(cn);
        }
    }

	gs.print('lowestImpactChangeNumbers = ' + lowestImpactChangeNumbers)

    return lowestImpactChangeNumbers;
}

// Call the indicator function
calculateIndicator('c83c5e5347c12200e0ef563dbb9a7190'); // Please give the dynamic variable for sys_Id

Result 

SarthakKashya2_0-1714120799930.png

 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards

Sarthak

Hi, I did not see much different of the solution as it was mostly an addition of gs.print and comment to use dynamic variable for sys_Id which at the initial example provided has the current.caused_by which is an Ref to the Change number from the Incident. 

 

My approach is to try to create each script to by individual indicators to find the lowest of 2  or 3 or 4.