Records not inserted in sys_history_line table

deepak50
Tera Contributor

Hi,

I have written a logic in script include to check how many times a field of Case updated. For this I am querying sys_history_line table with case set id.

The records are inserted in this table for case when case is created manually using case form. But records are not  inserted in this table when cases are created using GlideRecord Script.

Is there any reason why Records not inserted in sys_history_line table while created through script and how can we fix this issue.

 

Thanks

Deepak

2 ACCEPTED SOLUTIONS

James Chun
Kilo Patron

Hi @deepak50,

 

Refer to the documentation for the details - https://docs.servicenow.com/bundle/washingtondc-platform-security/page/administer/security/concept/c...

 

Long story short, History Set [sys_history_line] is generated when a user creates or views the history of a record (e.g. right-click the header menu and select History > List).

Also, it's worth noting that the History Set record will be deleted when not used after x number of days and will be recreated when someone views the history again.

 

With your requirement, you won't be able to use the History Set table as it's highly likely that the data won't be available and of course, you can't use the Audit [sys_audit] table as well.

 

Does your record have a field that tracks the total number of updates?

What is your use case for this?

 

Thanks

View solution in original post

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

James is spot on. For what you are describing, sys_history_line is by far not the right go to. This table is only populated with records from when someone manually views the history of specific records (and so also not the updates after this).

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

7 REPLIES 7

deepak50
Tera Contributor

Hi All,

Thanks for your reply, The use case is to count the number of times some field is updated in Case record.

I also read in some docs that querying sys_audit table from script is not good from performance point of view. since it stores large number of records and new records are always inserted in this for different type of tables

 

Thanks

Deepak

Hi @deepak50,

 

Which field are you trying to count? And what are you going to do with that information?

 

Cheers

Sumanth16
Kilo Patron

Hi @deepak50 ,

 

Check the glide.sys.audit_inserts system property. If it is set to false, then no audit record will exist for the initial insert of a record, and only updates will archived on the sys_audit table.

Also, note that the data you can see when viewing the history of a record (actions menu > History > List) is not the sys_audit table, it is the sys_history_line table, so initial inserts may be captured here but not reflected in the sys_audit table.

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda