Update or replace existing comments or work notes in Incident Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 02:49 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 03:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 03:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 03:53 AM
Hi,
what's your business requirement?
what should happen on click of UI action
Can you share complete script and some screenshots?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2022 04:50 AM
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.