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

matthew_magee1
Giga Guru

You can query the sys_history_line table and run a query like this:

find_real_file.png

Might not be 100% accurate because the ticket could be passed around a few times and left blank. There's a way to query the table via script include and get back the first entry per INC. I can help if you need assistance

Thank you so much for your prompt response. I would like to get a report of when first assigned to field got changes. If you could please help. 


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

Saloni-

The other responses are correct, technically you should not report on history tables. In fact, SN blocks the ability to run queries on these tables (ex: creating reports on the sys_history_line table.

Jagjeet Singh's solution would work going fwd. If you want to query the sys_history_line table, hopefully not impacting any performance on your system, you can open that table via the filter navigator (sys_history_line.list) and do something like this:
 
find_real_file.png
 
You could then export the rows and do what you'd like w/ the data. Again, if there are a ton of records, it could impact your performance. 
 
Technically we can still run a report via a script to get back the INC. I'll post that soon

Sruthi M
Kilo Guru

You can use sys_history_line table to run report and use condition like below. But ServiceNow doesn't recommend running report on historic tables as this will be huge data load on ServiceNow platform. It can cause performance issues

find_real_file.png

Hope this helps you out. If so, please hit the "Correct answer" button.