Howto get the user name from journal field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2024 05:42 AM
Good Day!
I wanted to write a script to get the journal entry, that is updated by user.
For example, in my instance there are some task SLAs updated with stage and post which some other updated happened and updated field got changed and those updated field will not captured in activity, but sys_updated_on was changed to recent updated user.
var current = new GlideRecord("task_sla");
current.addQuery('sys_id', '08b87a3633515e10e2820f248d5c7ba1');
current.query();
if (current.next()) {
gs.print(current.comments.getJournalEntry(-1));
or
gs.print(current.work_notes.getJournalEntry(-1));
}
kindly suggest which back ground scrip will help me to get the user name from journal field.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2024 07:06 AM
Hi @NVSN ,
On task sla table we dont have comment filed, in activities audit value are display, you can glide record on "sys_history_line" table and use order by updated, set limit 1. from result get user name.
Or if you are planning to get it for comment which is jounral field then glide record "sys_journal_field" like below.
var gr = new GlideRecord("incident");
gr.addQuery('sys_id', 'ffca41898371d610a9589780deaad3cd');
gr.query();
if (gr.next()) {
gs.print(gr.comments.getJournalEntry(-1));
}
var gr = new GlideRecord("sys_journal_field");
gr.addQuery('element_id', 'ffca41898371d610a9589780deaad3cd');
gr.addQuery('element','comments');
gr.query();
if (gr.next()) {
gs.print(gr.sys_created_by);
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------