The CreatorCon Call for Content is officially open! Get started here.

PAIN Value Calculation

karl_james
Kilo Explorer

Hi All

I've been pretty good with my scripting within SN but I'm having an issue that I'm hoping someone can help with. Our Problem Manager asked for a PAIN value field to be added to our problem form, which is all good.

I'd like to write a script to calculate the PAIN value and populate the field to save some time and increase accuracy of the values for reporting. Below is the calculation to get this value:

(V x Y) x Z = PVC

V = Severity of each related Incident

  • Severity 1 = 1000 points
  • Severity 2 = 800 points
  • Severity 3 = 500 points

Y = Number of related Incidents x V

Z = Total Outage Hours x Y

Has anyone done anything like this before?

1 ACCEPTED SOLUTION

Your X and Y values ...



var severityArray = [];
severityArray["1"]=1000;
severityArray["2"]=800;
severityArray["2"]=500;


var X = severityArray[current.severity];


var count = new GlideAggregate('incident');
count.addEncodedQuery('parent='+current.sys_id);
count.addAggregate('COUNT');
count.query();
var Y = 0;
if (count.next())
Y = count.getAggregate('COUNT');


View solution in original post

15 REPLIES 15

I just re-read the OP's original formula, he stated, "Severity of each related Incident".


It appears you provided the Severity of the Problem ticket itself.



I'd adjust as follows to get the correct "V" value, which must be multiplied by "Y" each time according to the formula:



var severityArray = [];
severityArray["1"]=1000;
severityArray["2"]=800;
severityArray["2"]=500;



var VtimesY = 0;


var count = new GlideAggregate('incident');
count.addEncodedQuery('parent='+current.sys_id);
count.addAggregate('COUNT');
count.query();
var Y = 0;
if (count.next()) {
  Y = count.getAggregate('COUNT');


}


var incidentGR = new GlideRecord('incident');


incidentGR.addEncodedQuery("parent="+current.sys.id);


incidentGR.query();


while (incidentGR.next()) {


  VtimesY = VtimesY + (severityArray[incidentGR.severity] * Y);


}



So, now you just have to multiply VtimesY by the Duration of the Outage record attached to the Problem


That's great, thank you Robert for your input, I'll give this a go!


My bad ... I goofed up the formula .. Thanks for pointing this out ...


karl_james
Kilo Explorer

What would you guys say best practice is with this, should I do this as a client script or business rule?


I would suggest that due to the calculations, this is an onUpdate() Business Rule.  


There are actually probably two, one on the Incident table and one on the Problem table.



The Incident table BR would run when the condition matches:


current.parent.changes() || (current.severity.changes() && !current.parent.nil())



(you want to run if the Incident is attached to a Problem, or if the Incident's severity changes AND it is already attached to a problem)



The Problem table BR would run whenever the Problem is updated, since you'll have to pull the Outage duration at that time and recalculate.   You probably want to devise a condition, since not every problem will have child incidents, and according to your formula, a Problem without child Incidents doesn't have a PAIN value.