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

SumanthDosapati
Mega Sage
Mega Sage

Hi @Enrico Domingo 

This link might solve your query Remove/Update Journal entries.

 

Regards,
Sumanth

already tried this one, but i just don't know what action name and table we should put in the UI action. we are so new with service now and unfamiliar with this.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

what's your business requirement?

what should happen on click of UI action

Can you share complete script and some screenshots?

Regards
Ankur

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

Hi Ankur,

So what we did is, we add new button by UI Action, and have a script above. In the script we get all the comments/work notes in the Incident. What we want to do now is replace the value of all comments with the word that we want to add to the comment before it renders to the Incident page. or we can update the incident table.