Priority duration metric calculation

KeithM2
Kilo Contributor

I have a client who is requesting a report/list of incidents whose priority has changed.   I'm able to come up with a metric definition that looks at the priority field and it works fine (I'm using the type Field Value Duration).   The problem that I'm having is the client wants to skip the initial priority and just list if the initial priority changes.   For example, if the incident is opened as a priority 3, gets reassigned twice and then gets changed to a priority 2, only show the change from P3 to P2.   Right now the way the metric definition works, it captures when the ticket is opened and assigned the original P3 priority.   I'm sure there is a way to do this I just have no clue how.   Any ideas?

1 ACCEPTED SOLUTION

Sorry Keith my bad, read as you had it as a script metric :$ - hence "// Create metric instance" comment (was expecting you to copy and paste into there)



So redone for you below, complete with script code.



// variables available


// current: GlideRecord -   target incident


// definition: GlideRecord -   (this row)


if (current.sys_mod_count > 0) {


  var mi = new MetricInstance(definition, current);


  var gr = mi.getNewRecord();


  gr.field_value = current.priority;


  gr.field = null;


  gr.calculation_complete = true;


  gr.insert();


}



Definition picture:



TS Priority Calculation.PNG



Had to do away with isNewRecord(), didn't work - used sys_mod_count instead.



Thanks



Tim


View solution in original post

6 REPLIES 6

Tim75
Mega Expert

Hi Keith



Try adding a condition to only record an instance if the current record isn't new i.e:



if (!current.isNewRecord()) {


  // Create metric instance


}



That should allow you to prevent instances being record upon initial save.   Let me know if that works for you.   If you're still having trouble paste the definition in here and I'll take a look for you.



Thanks



Tim


KeithM2
Kilo Contributor

Tim,



Thanks for the response.   Unfortunately, it didn't work.   I've attached a screenshot of what the metric definition currently is (including the change you recommended).   I have a feeling that this may take a script instead of just the Field Value Duration.priority metric definition.JPG


Sorry Keith my bad, read as you had it as a script metric :$ - hence "// Create metric instance" comment (was expecting you to copy and paste into there)



So redone for you below, complete with script code.



// variables available


// current: GlideRecord -   target incident


// definition: GlideRecord -   (this row)


if (current.sys_mod_count > 0) {


  var mi = new MetricInstance(definition, current);


  var gr = mi.getNewRecord();


  gr.field_value = current.priority;


  gr.field = null;


  gr.calculation_complete = true;


  gr.insert();


}



Definition picture:



TS Priority Calculation.PNG



Had to do away with isNewRecord(), didn't work - used sys_mod_count instead.



Thanks



Tim


KeithM2
Kilo Contributor

Tim,



This worked perfect.   It captured just what the client was looking for.   I appreciate the help!!



As usual, they always want something more.   Is there a way to capture who made the priority change?   I know I can use the "updated by" field but the last person who updates the ticket may not necessarily be the one who changed the priority.   Any thoughts?