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

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

i'm having an infinite loop by doing this.find_real_file.png

Hi,

client checkbox - uncheck

onclick field - uncheck

var gr = new GlideRecord("sys_journal_field");
gr.addQuery('name', 'incident');
gr.addQuery("element_id", current.sys_id); // add this query
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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar like this one?

i was redirected to this page.find_real_file.png

Hi,

is the script working fine?

update as this

action.setRedirectURL(current);

Regards
Ankur

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