Update or replace existing comments or work notes in Incident Page

Enrico Domingo
Kilo Contributor
function commentsDialog() {
    gsftSubmit(null, g_form.getFormElement(), 'comments_dialog');
}

var gr = new GlideRecord("incident");
gr.addQuery('number', current.number);
gr.addQuery("element", "comments");
gr.query();

if (gr.next()) {
    var notes = gr.comments.getJournalEntry(-1);
    //gets all journal entries as a string where each entry is delimited by '\n\n'
    var na = notes.split("\n\n");

    //stores each entry into an array of strings
    for (var i = 0; i < na.length; i++) {
        var data = na[i];
        gs.addInfoMessage(data);
       gr.comments = "testing " + i;
        gr.update();
    }
}

action.setRedirectURL(gr);

How to replace or update all existing comments/work notes in an Incident.

Here we are able to get all comments but we want to update it by adding some text to it instead of adding a new one.

 

14 REPLIES 14

like this comments/work notes. we are seeing testing 0, testing 1, testing 2 and testing 3 comments.

 

we want to add to those comments like "testing 0 - {Add something text Here}"

find_real_file.png

Hi,

the above script is not complete one

please share the complete script

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

thats the complete script in the UI Action. i don't know what script are you looking for.

Hi,

make your UI action as server side and use this code

Uncheck Client checkbox on UI action

Clear the Onclick field on UI action

var gr = new GlideRecord("sys_journal_field");
gr.addQuery('name', 'incident');
gr.addQuery("element", "comments");
gr.query();
while (gr.next()) {
	gr.value = "testing - " + gr.value;
	gr.update();
}
action.setRedirectURL(gr);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar like this one?

find_real_file.png