How to get first additional comment in incident record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 10:15 AM
I want to get the first ever Additional comment from the incident record.
I have tried below in the flow designer action to get last comment, but not able to get first comment of incidet record
Script for Flow designer-Action:-
var grTask=inputs.task;
outputs.varcomment=grTask.work_notes.getJournalEntry(1).toString();
according to above script I am getting last commet, but if I replace 1 as -1, I am getting error.
Can anyone pease help me to get 1st additional comment please !!!!!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 11:18 AM
Hello @chandan15 ,
-1 will give you entire additional comment of the ticket.
For this u can just go to the sys_journal_field table and query for the information you are looking for.
Or write logic in BR, with condition when additional comments changes.
Or u can do by storing all values in the array and get the value of first one, like this :
var notes = current.work_notes.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++) gs.print(na[i]);
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 03:02 AM
Hi Khusboo, you are right. By using(-1) we can get all the comments but we are getting error in flowdesigner.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 03:06 AM
Hello @chandan15 , can you please try this workaround :-
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0825611
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2023 02:27 PM
This post got me going in the right direction, but I think it can be cleaner. In my testing the first comment is always the total count of elements in the array -2. Therefore if we take your script, we don't have to do a for loop. I added another line at the end that strips off the user and date info if all you want is the work note text.
var notes = current.work_notes.getJournalEntry(-1);
//gets all journal entries as a string where each entry is delimited by '\n\n'
var na = notes.split("\n\n");
gs.print(na[na.length-2]);
// this strips off the user and date info and just leaves the work note text.
gs.print(na[na.length - 2].match(/\n.*/gm).join('').replace(/^\s*\n/gm, ""));