How to retrieve sys_history_line records for a specific record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi Everyone,
I have a question regarding retrieving records from the sys_history_line table.
In my scenario, a record was created and updated a long time ago. Over time, the related entries in sys_history_line were deleted. However, when I open the record again or navigate to History → List, the system regenerates the history lines, and I’m able to fetch that data using a background script.
My requirement is to retrieve those sys_history_line records without opening the record or navigating to the History UI, i.e., without triggering regeneration manually.
Is there a way to access or regenerate these history records programmatically?
Any guidance would be appreciated. Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @NAVAYUVANS
The Audit [sys_audit] and History Sets capture the same data, but data is managed differently. The major difference between them is persistence:
- The Audit table [sys_audit] records persist forever.
- The History Set [sys_history_set] records are generated on use and are removed by the table cleaner 30 days after their most recent use.
- The History Set Line [sys_history_line] records are on four tables that are managed using Table Rotation, which is customizable. From the base system, the tables are rotated on a seven-day basis, meaning that the records are dropped 28 days after generation unless they are requested again.
Once you Open the record -> right-click on the header or the hamburger menu icon->select History from the menu->List : History set and history line records will be generated from the sys_audit table.
Refer following KBs:
History sets - How are they generated
KB0547662:Auditing and history sets | How they work together
https://www.servicenow.com/community/developer-forum/how-to-fix-deleted-record/m-p/3474488
