- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2020 02:12 PM
Hi Experts!!
I made a Metric definition, Type: Script calculation, in Defect [u_defect] table.
This script monitors the status change of the defect from when it is opened until it goes to Inspection. The code works fine but I would like to know how I can take the duration value that the metric does and put it in another duration field inside the defect table.
Any ideas please?
add Image and link below:
var s = current.state;
if (s == 2) //2 == Inspection
createMetric();
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.start = current.opened_at;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2020 11:18 PM
Add the update action to the metric:
var s = current.state;
if (s == 2) //2 == Inspection
createMetric();
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.start = current.opened_at;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
var grCurrent = new GlideRecord("incident");
if (grCurrent.get(current.sys_id)) {
grCurrent. < DURATION FIELD > = gr.duration;
grCurrent.update();
}
}
Replace <DURATION FIELD> with the duration field you want to fill and "incident" with the table you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2020 11:18 PM
Add the update action to the metric:
var s = current.state;
if (s == 2) //2 == Inspection
createMetric();
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.start = current.opened_at;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
var grCurrent = new GlideRecord("incident");
if (grCurrent.get(current.sys_id)) {
grCurrent. < DURATION FIELD > = gr.duration;
grCurrent.update();
}
}
Replace <DURATION FIELD> with the duration field you want to fill and "incident" with the table you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2020 07:12 AM
Thanks a lot Willem it works