Report on historical data

Saloni Suthar
Mega Sage
Mega Sage

Hey everyone,

I would like to pull when assigned to field got changed for the first time on the incident table from the history sets table. Is it possible? I would not like to use PA for reporting. Please let me know if anyone can help me with the script or has any better insights. I really appreciate it


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni
1 ACCEPTED SOLUTION

JagjeetSingh
Kilo Sage

Hi,

Do not use history table. Instead use a metric to serve your purpose.

Follow the steps.

1. Check out the OOB metric for incident table named "Assigned to Duration". This metric calculates the duration for how much time the incident was assigned to a particular person.

2. Now your requirement is to get the time stamp when the assigned to field was changed first time. For this create a copy of the "Assigned to Duration" metric. In script area paste below script. This will create the record only once for each incident in metric_instance table.

createMetric();
function createMetric() {

var mi = new MetricInstance(definition, current);

if (mi.metricExists()){
return;}
else{
var gr = mi.getNewRecord();
gr.insert();
}
}

3. That's it! From now onwards it will start to capture the metrics. Create report on incident_metric table(it is database view actually) and use below filters. 

find_real_file.png

//Change the definition with the name of your metric.

4. Add below highlighted field to report to get the time stamp when the field was changed.

find_real_file.png

 

Mark my response correct if it worked for you. Ask for help if required.

 

Jagjeet Singh
ServiceNow Community Rising Star 2022/2023

View solution in original post

5 REPLIES 5

JagjeetSingh
Kilo Sage

Hi,

Do not use history table. Instead use a metric to serve your purpose.

Follow the steps.

1. Check out the OOB metric for incident table named "Assigned to Duration". This metric calculates the duration for how much time the incident was assigned to a particular person.

2. Now your requirement is to get the time stamp when the assigned to field was changed first time. For this create a copy of the "Assigned to Duration" metric. In script area paste below script. This will create the record only once for each incident in metric_instance table.

createMetric();
function createMetric() {

var mi = new MetricInstance(definition, current);

if (mi.metricExists()){
return;}
else{
var gr = mi.getNewRecord();
gr.insert();
}
}

3. That's it! From now onwards it will start to capture the metrics. Create report on incident_metric table(it is database view actually) and use below filters. 

find_real_file.png

//Change the definition with the name of your metric.

4. Add below highlighted field to report to get the time stamp when the field was changed.

find_real_file.png

 

Mark my response correct if it worked for you. Ask for help if required.

 

Jagjeet Singh
ServiceNow Community Rising Star 2022/2023