Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Script to calculate 'Create' to 'Contain' Duration - Security Incidents in specific Assignment Group

WazzaJC
Tera Expert

Dear ServiceNow Community colleagues,

 

I would greatly appreciate any advice/direction, on what I need to update in the following script (see below & screenshot attached).

 

It is currently (almost) working fine, it calculates the duration time, between the time a Security Incident is created and the time when the 'State' changes from 'Created' to 'Contain'.

 

But I want this to only function for Security Incidents assigned to the 'Security Analyst' assignment group.

 

What would be the adjusted script, to ensure this metric definition calculation, only functions for those Security Incidents assigned to 'Security Analyst' assignment group?

 

Many thanks for any help/guidance on this (please see my existing script below).

 

// variables available
// current: GlideRecord -  target incident
// definition: GlideRecord -  (this row)
var s = current.state;
if (s == 18)
    createMetric();

function createMetric() {
    var mi = new MetricInstance(definition, current);
    if (mi.metricExists())
        return;

    var gr = mi.getNewRecord();
    gr.start = current.sys_created_on;
    gr.end = current.sys_updated_on;
    gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
    gr.calculation_complete = true;
    gr.insert();
}

 

1 REPLY 1

Nilesh Pol
Kilo Sage

@WazzaJC use below updates script:

// variables available
// current: GlideRecord - target incident
// definition: GlideRecord - (this row)

// Check if the state is 'Contain' (value 18) and the assignment group is 'Security Analyst'
if (current.state == 18 && current.assignment_group.getDisplayValue() == 'Security Analyst') {
createMetric();
}

function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists()) {
return;
}

var gr = mi.getNewRecord();
gr.start = current.sys_created_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
}