Background script | GlideRecord Query not working properly for sys_history_line table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2022 09:40 AM
Hi everyone,
I stumbled upon a really weird issue I can't wrap my head around.
I am trying to populate a date field in a table based on historical data of specific field-updates ("Status" field updates in the sys_history_line table of the records).
Since I am dealing with ~1600 records, I wanted to accomplish this via a background script - you can find the code below and in the attached screenshot.
The script gets all records of a custom extension of the task table, that are in any closed state and tries to query for those records sys_ids in the history table with the "state" field requirement.
When testing this on single records with their individual sys_ids, I don't have any issues, but when applying it to all 1600 records, I get for most records no match - even though each record that is in a closed state, has to have a historic event, where the state was actually set to any of those closed states.
However, and this is the weird part, once I open a record in the environment manually (List of records of the queried table, and simply opening any of the records), this record will then be queried correctly with the script, but not before that.
My question:
> Is there any necessity to initialize records in an environment before the referencing with the sys_history_line tables work? When testing myself, I can also not use the "Set" column of the sys_history_line table for filtering manually, before I have not opened the record, I am looking for, at least once.
Background:
> The DEV environment I am working in was just mirrored a few days ago from the production environment
I welcome any feedback that might help me to understand the underlying issue here and how to resolve it without opening each individual record before running the script.
Many thanks in advance!
Script below
_________________________________________________________
_________________________________________________________
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2022 07:40 AM
Hi Dan,
many thanks again for your reply.
I have actually tried it with both constructors already before, but it won't change the actual result.
When using the modifier "true" (sys_audit) the result is the following:
and when using the modifier "false" (sys_history_set) the result is the following:
-> Nothing really changes, and the output with the true modifier is actually even more confusing.
Anyway, I have tried it on my PDI and there it seems to work as expected (just tried a small sample). My assumption is therefore, that something might be set up weirdly in the client-environment.
I assume there will be no proper solution and I will just have to go with the half-valid solution - opening every relevant record once to load it into the sys_history_line table, then run the initial script...
Many thanks again for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2022 08:20 AM
Hi Philipp,
I apologize for not realizing this sooner. In hindsight I realize that this is the first thing that should have been checked. My guess is that the table is not being audited. If this is the case, unfortunately, you won't be able to retrieve any of this data from either the History Set or Audit data.
In my opinion, the easiest way to check if a table is being audited is to find the Collection type Dictionary Entry [sys_dictionary] record for the table (there will only be one for each table). You want to check the value in the Audit column.
I'm very sorry for any inconvenience, or false hope this might have caused. On the bright side, maybe HistoryWalker will come in handy for you at some point in the future.
Best regards,
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2022 01:57 AM
Hi Dan,
I hope you had a good weekend. And do not worry, that you have not mentioned it before, since both of them have their "audit" box checked for the collection dictionary entry... Meaning there must be something wrong with records / instance in general.
I am really grateful for your suggestions but will not pursue this issue further due to time constraints.
Sometimes the simple solution is also the best to implement ... it will include some "manual" work this time I guess ;).
Cheers,
Philipp