Need help for Metric definition to create whenever request gets created

sony8
Tera Contributor

Hello Everyone,

 

I am working for custom application, 

the requestor submits request from Service portal. after submission request will be created on Custom Request Table.

 

my requirement is

when Request gets created from Portal on my Custom Request table , the request state is in Open State.

My Metric Instance record also need to created on the Metric instance table at same time.

 

and if state changes to Work in progress another Metric Instance record should be created.

 

I tried the below script using Metric definition, But the timestamp was varying.

var curTime=current.opened_at;
var a=gs.nowGlideDateTime();
gs.info("test567"+a);
gs.info("test567"+curTime);
// is timestamp diff btw curTime and a is  of 2 secs how to get through this issue
	createMetric();


function createMetric() {
    var mi = new MetricInstance(definition, current);
	if (!mi.metricExists()) {
		gs.info("test567");
        var a = mi.getNewRecord();
        a.start = current.sys_updated_on;
        a.value = current.getDisplayValue('state');
        a.calculation_complete = false;
        a.insert();
        return;

	}
}

 

 

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@sony8 

did you check the metric definition for incident state which is out of the box?

you can have something similar.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar  I have checked it with the help of it i have implemented this but now i am facing issue with 

a and curtime. there is some seconds difference and causing issue. anything am i missing?