can we query sys_history_line table ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 12:06 AM
Hi All,
need suggestion on query sys_history_line table, is it a good idea to do so. As the table contains huge number of records, which keeps growing. So if a business requirement needs to query this table, shall we decline the requirement. or can we accept it. What we want to check is if a field was modified in last 5 days.
Regards
Kapil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 12:19 AM
If you query for the data in last 4 weeks, it is ok otherwise you should not rely one sys_history_line table. As the data in this table is dependent on sys_history_set table to form the relation, which will be cleaned up every 30 days.
From my personal experiences, my recommendation is not to use this table. Instead you can create a metric for the field and query the metric instance to check if the value is changed in last 5 days or what ever.
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 12:38 AM - edited 10-18-2023 12:40 AM
Hi there,
What is your actual use case to query this table?
In my opinion: avoid as much as possible! Why? This table is only populated when end-users MANUALY view the history of records. If no one did that, you are quering incorrect data / data which is not present.
So avoid this as much as possible. Especially when I read "What we want to check is if a field was modified in last 5 days". Than this is not the table to query!
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 12:38 AM - edited 10-18-2023 12:39 AM
What is a good idea, to maintain this table. For example using Table Cleaners.
This one is also mentioned in one of my blogs:
https://www.servicenow.com/community/now-platform-blog/keeping-your-instance-database-footprint-tidy...
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2023 12:42 AM
The table should be used is the Sys Audits [sys_audit].
We should not look for data in the sys_history_line table. Refer to this KB #KB0744473
Let me know if it works for you.
Cheers,
Tai Vu