The CreatorCon Call for Content is officially open! Get started here.

Metric definition defined but not creating metric instances

akshay parekar1
Tera Contributor

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();
}

 

2 REPLIES 2

Amit Gujarathi
Giga Sage
Giga Sage

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();
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



@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