Need a script to populate previous sys_journal_line reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2024 08:44 AM - edited ‎03-19-2024 08:56 AM
Hello,
I've recently added a reference field (u_user) on the sys_journal_line table that will default the user who submits it (javascript: gs.getUserID();). This was done in large part because it's very difficult to report on the system string fields of created_by and updated_by. This is working perfectly for new entries as it shows the created_by's display value.
However now, I want to go through all of the previous journal entries to populate the u_user reference field. How can I achieve this? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-19-2024 09:36 AM
Hi @TramaineM ,
I think you need to get user values from the sys_audit table not in sys_journal_line table. All the changes made on record store in 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2024 03:44 AM
Hi @TramaineM ,
Remember to test this script in a non-production environment first to ensure it behaves as expected. Once verified, you can execute it as a Fix Script in your PROD instance.
var journalGr = new GlideRecord('sys_journal_line');
journalGr.addNullQuery('u_user');
journalGr.query();
while (journalGr.next()) {
var createdBy = journalGr.getValue('created_by');
var userGr = new GlideRecord('sys_user');
if (userGr.get(createdBy)) {
// Set the u_user field with the user reference
journalGr.u_user = userGr.getUniqueValue();
journalGr.update();
}
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Subhashis