How to get first additional comment in incident record

chandan15
Tera Contributor

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 !!!!!!!!

4 REPLIES 4

Community Alums
Not applicable

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!

Hi Khusboo, you are right. By using(-1) we can get all the comments but we are getting error in flowdesigner.

Community Alums
Not applicable

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, ""));