Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to update comments or work notes in incidents in UI Action?

Laida Garcia
Kilo Explorer

Hi. I am trying to update the value of all comments and work notes using button in UI action. But instead of updating it just added. Ex. change  'Sample123' to  'Sample Text Change'find_real_file.pngfind_real_file.png

6 REPLIES 6

Sagar Pagar
Tera Patron

Hi Laidda,

You will see comments and work-notes "Sample123" when you click the UI action (lines 16 and 17).

gr.comments = "Sample123";

gr.work_niotes = "Sample123";

 

What exactly do you want to add to comments and work-notes?

 

Thanks!

Sagar Pagar

The world works with ServiceNow

we don't want to add new comments/work notes. we need to update the existing comments/work notes by adding something to the text.

Maik Skoddow
Tera Patron

Hi @Laida Garcia 

comments and work notes are stored at table sys_journal_field

If you want to update all existing work notes and comments you have to load that lists, iterate them and update each record individually.

 

gr.work_notes.getJournalEntry(-1); // this gives you all the entries for work notes

gr.comments.getJournalEntry(-1); // this gives you all the entries for comments

 

Kind regards
Maik

Hitoshi Ozawa
Giga Sage

Hi Laida,

>change  'Sample123' to  'Sample Text Change'

Not sure why the sample code is setting to "Sample123" instead of "Sample Text Change".

gr.comments = "Sample123";
gr.works_notes = "Sample123";

Anyways, to change comments and work notes, query on "sys_journal_field" instead of "incident" table.

var gr = new GlideRecord('sys_journal_field');
gr.addEncodedQuery('name=incident^element=work_notes^ORelement=comments');
gr.addQuery('element_id', current.sys_id);
gr.query();
while (gr.next()) {
    gr.setValue('value', 'Sample Text Change');
    gr.update();
}