How to access "new" column in sys_history_line?

e_wilber
Tera Guru

There is an OOB field named "new" on sys_history_line. When you try to glidequery to the record and print rec.new you get an error "Compiler exception: missing name after .".

 

How do I access this field value?

var his = new GlideRecord('sys_history_line');
his.addQuery('set', '20e5c76893abfd5061dcba1e1dba1036');
his.query();

while (his.next()) {
    gs.print(his.getValue('new')); // This returns no data at all
    gs.print(his.new); // This returns the compiler error
}

 

4 REPLIES 4

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

Just out of curiousity, what's the business case to query sys_history_line table? Just asking because often (9 out of 10 times) people are not aware how this table is actually populated and that this is the wrong table for their business case.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

There is a specific journal field on this table we need to pull in all of the logs for (where we can display the timestamp, the user, and the "new" value) inside a custom section we have in UI builder.


We need to apply formatting around these separate data fields rather than just pulling from record.work_notes which contains everything all mixed together, so we want to pull directly from the source where the fields are separted.

You can just use _new as I mentioned in the other reply. So with that this question should be resolved 😀

 

Why asking for the use case, because you do need to be aware how the data in sys_history_set and sys_history_line are populated and when it is being cleaned up. As this data is only generated when someone manually views the history of a record. So if you would use this for reporting purposes... you might end up with completely incorrect results. Also out-of-the-box there is a Table Cleaner which cleans up this data after a certain amount of time.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Regarding your code itself, try:

 

gs.print(his._new);
 
So with a underscore. Works fine.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn