Metric definition defined but not creating metric instances
This content was last updated in 2023. It may still be useful, but could contain outdated information. Please confirm its accuracy before relying on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 02:17 AM
Hi everyone,
I have created one metric definition and based on logic defined within it, i completed assessment .
But metric instance didn't got created
I am adding script here, can anyone please let me know whats the issue?
var attest = current.metric_type.getDisplayValue();
if (attest== "GRC Attestation") {
var s = current.state;
if (s == 'complete')
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 03:30 AM
HI @akshay parekar1 ,
I trust you are doing fine.
Here's a revised version of the script with some modifications to address the potential problem:
var attest = current.metric_type.getDisplayValue();
if (attest == "GRC Attestation") {
var s = current.state;
if (s == 'complete')
createMetric();
}
function createMetric() {
var mi = new MetricInstance(current.metric_type, current);
if (mi.metricExists())
return;
var gr = new GlideRecord('metric_instance');
gr.initialize();
gr.metric_definition = mi.metric_definition;
gr.source = mi.source;
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 05:31 AM
@Amit Gujarathi Thanks for replying, i tried with your modified code, bot didn't work.
And why do we need to pass metric type there, i didn't get