Howto get the user name from journal field

NVSN
Tera Contributor

Good Day!

 

I wanted to write a script to get the journal entry, that is updated by user.

NVSN_1-1731677092386.png

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.

 

I executed the below script with two different methods, but no use.

 

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.

 

1 REPLY 1

Runjay Patel
Giga Sage

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.

RunjayPatel_0-1731683193252.png

 

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

-------------------------------------------------------------------------

 

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...