- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2022 09:40 AM
Hi All,
The requirement is to calculate the duration between Incident Creation time to Resolver Group Assignment time. Could you please assist how to do this. We need to create a metric for each incident.
Eg:
Inc000001
Created and Assigned to SD -> 10 AM
SD Assigned to A Group -> 11 AM
A Group sent back to SD -> 12 PM
SD Assigned inc to B Group -> 1 PM
B Group sent back to SD -> 2 PM
SD Assigned to C Group -> 3 PM (5 hours is time to taken to find the right assignment group, it needs to be stored in metric/each incident)
C Group is the right resolver team and resolved the incident.
Above details are getting stored in Sys_audit table.
Below is the BR created in incident table, need help on bold and lines.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var syid = current.sys_id;
var grpid = current.assignment_group;
var inctime = current.sys_created_on;
var mttdtime;
gs.log('MTTD Calc '+ 'Sysid ' + syid + 'Assignment Group '+ grpid + 'Inc Created time ' + inctime);
var gr = new GlideRecord('sys_audit');
gr.addEncodedQuery('documentkey',syid);
gr.addEncodedQuery('newvalue',grpid);
gr.addEncodedQuery('fieldname','assignment_group');
gr.setLimit(1);
gr.query();
if (gr.next())
{
var agrptime = gr.sys_created_on.getDisplayValue();
gs.log('Assignment Grp Time ' + agrptime);
mttdtime = agrptime - inctime;
current.u_mttd = mttdtime;
gr.update();
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2022 08:33 AM
Getting the "touched" time is going to be more difficult because there's no field that tracks that. You're going to have to do a lookup on OTHER metric instances ... specifically the field tracking one for state and get the first instance of a state change to assigned.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2022 08:54 AM
It'd take me an hour or two to build, so no, I can't build and share that.
Metrics are on your instance under this metrics menu:
Specifically the metric_definition table.
Metric Definitions have two types: Field Value Durations & Script Calculations
Look at the Script Calculation versions to get a field for how they work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2022 02:17 PM
Rob, Have visited the Metric Instance and found unique entry to get the start time of assigning the incident.
And modified the BR as below, however its not going inside if statement.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var syid = current.sys_id;
var grpid = current.assignment_group.getDisplayValue();
var inctime = current.sys_created_on;
var mttdtime;
gs.log('MTTD Calc ' + 'Sysid ' + syid + '\nAssignment Group ' + grpid + '\nInc Created time ' + inctime);
var gr = new GlideRecord('metric_instance');
gr.addEncodedQuery('id=syid^definition=cd0d74071b2190504d05db12cd4bcbc2^valueSTARTSWITHgrpid');
gr.setLimit(100);
gr.query();
if (gr.next()) {
gs.log('MTTD Calc inside if ' + gr.sys_id);
var agrptime = gr.start;
gs.log('MTTD Calc inside if agrptime ' + agrptime);
var diff = gs.dateDiff(gr.start, current.sys_created_on, false);
gs.log('Diff Time ' + diff);
gs.log('Assignment Grp Time ' + agrptime);
mttdtime = agrptime - inctime;
current.u_mttd = mttdtime;
gr.update();
}
})(current, previous);
Log Output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2022 06:50 PM
DO NOT MODIFY OOB Metric Definitions.
Always copy & Rename.
Unfortunately I'm tied up in something right now, I can take a look at this late tomorrow. Sorry for the inconvenience.
If its been a couple days and I haven't checked back, feel free to DM me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2022 04:25 AM
Rob, Able to get the Incident Touched time. Now only thing is to get duration between Incident created and Incident touched.
if (gr.next()) {
gs.log('MTTD Calc inside if ' + gr.sys_id);
var agrptime = gr.start;
gs.log('MTTD Calc inside if agrptime ' + agrptime);
dur = gs.dateDiff(agrptime, inctime);
var dateDifference = new GlideDuration(dur);
gs.log("dateDifference : " + dateDifference);
var d = dateDifference.getDayPart();
gs.log("d :" + d);
var diff = gs.dateDiff(gr.start, current.sys_created_on, false);
gs.log('Diff Time ' + diff);
gs.log('Assignment Grp Time ' + agrptime);
mttdtime = agrptime - inctime;
current.u_mttd = mttdtime;
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2022 08:33 AM
Getting the "touched" time is going to be more difficult because there's no field that tracks that. You're going to have to do a lookup on OTHER metric instances ... specifically the field tracking one for state and get the first instance of a state change to assigned.