Querying sys_history_line

Jamsta1912
Tera Guru

Hi all,

I'm trying to create what is effectively a custom log, that records updates to particular fields on records of a particular type. I'm fine with creating entries for the log for future updates to records - I have a business rule that reponds to updates to the fields of interest and creates an entry on the log.

I wanted to create 'historic' logs based on updates that have already happened. I have a script that 'scans' the sys_history_line table for the records, finds the relevant updates and then creates the log entries. However, I'm finding that sys_history_line can only be queried for a particular record if the record itself has recently been opened. So I'm guessing the entries on the sys_history_line table are somehow created 'on-the-fly' whenever a record is viewed. Is there a way to 'mimic' this, so that entries on sys_history_line relating to particular records become available to a GlideRecord query in a script?

I guess if not, I would have to query the sys_audit table.

Thanks

Jamie

1 ACCEPTED SOLUTION

Boyan1
Kilo Sage

Hi Jamie,

There is way to generate the sys_history_lina via GlideHistorySet. You can execute it as given below

new GlideHistorySet(<table name>, <record.sys_id>).generate()

e.g.

new GlideHistorySet("task", task.sys_id).generate();

 

Best regards,

Boyan

View solution in original post

2 REPLIES 2

Boyan1
Kilo Sage

Hi Jamie,

There is way to generate the sys_history_lina via GlideHistorySet. You can execute it as given below

new GlideHistorySet(<table name>, <record.sys_id>).generate()

e.g.

new GlideHistorySet("task", task.sys_id).generate();

 

Best regards,

Boyan

Thank you Boyan. That’s smashing :) Jamie