Querying sys_history_line table via API

bobbydouglas
Mega Guru

I have a requirement to reproduce the functionality of the Activity formatter in a portal we are creating.   I need to make API calls to capture the audit history for changes made to the additional comments and state fields.   My question is should I be concerned with querying the sys_history_line table to retrieve this information?   I am just looking for some best practice guidance here.   Thanks in advance for any advice you can offer.

1 ACCEPTED SOLUTION

srinivasthelu
Tera Guru

Hi Bobby,



sys_history_line is generally a large table and the queries against it comes with a cost!!.



however, make sure to have   sysparm_record_count to limit your results :



https://demo.service-now.com/incident.do?JSON&sysparm_query=sys_created_by=admin&sysparm_record_coun...


View solution in original post

3 REPLIES 3

srinivasthelu
Tera Guru

Hi Bobby,



sys_history_line is generally a large table and the queries against it comes with a cost!!.



however, make sure to have   sysparm_record_count to limit your results :



https://demo.service-now.com/incident.do?JSON&sysparm_query=sys_created_by=admin&sysparm_record_coun...


Thanks for the feedback Srinivas we are actually going to perform a few tests.   The developer of our portal is looking into limiting the pull to 10 records at a time.


Manolis Sgouro1
Tera Contributor

Hello,

The sys_history_line table is a big table and i think is getting rotated. That means, sometimes you are searching for a specific record and is not there.

I found the following code:

  var hs = new GlideHistorySet(glideRecord);
  var hs_sys_id = hs.generate();

Where "glideRecord" the Glide Record you are searching it's history lines.
These two lines of code will force the system to "pop-up" the records in the sys_history_line table that are related to your record.

I hope that helps.