How to get the comment that starts with a particular string

Bindhu1
Tera Contributor

Hi all,

I have a requirement where I have to get the specific comment from RITM to  catalog task that is created after approval.

I am handling it from the flow but it is not working as expected. I have to only get the comment that starts a particular string 'comment from approval note', but here I am getting the entire list of comments. Can anyone tell me how to get that comment that starts with a particular string, thanks in advance.

Bindhu1_0-1667921934936.png

 

7 REPLIES 7

Can you try this ?

var com = fd_data.trigger.current.requested_item.comments.getJournalEntry(-1).toString();
if (com.indexOf("comment from Approval note") > -1 ) {
    return com;
}
 
Regards,

Sebas Di Loreto
Kilo Sage
Kilo Sage

Hi @Bindhu1 

getJournalEntry(-1) means you get ALL comments.

The IF only checks if in ALL comments you find "comment from approval note", which you do on your tests.

Finally you are return com, which is ALL comments again.

Do this:

  • Get ALL comments into a string
  • Then store each comment on an array
  • Then evaluate each and return the one you want.

https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server_legacy/c_GlideElementAPI#r_Glid...

 

 

//gets all journal entries as a string where each entry is delimited by '\n\n'
var notes = current.work_notes.getJournalEntry(-1); 
//stores each entry into an array of strings
var na = notes.split("\n\n");  
                      
for (var i = 0; i < na.length; i++)                 
  gs.print(na[i]);

 

 


If I helped you with your case, please click the Thumb Icon and mark as Correct.


sprabakaran
Tera Contributor

Hello @Bindhu1,

 

Your code should be comments.getJournalEntry(-1).split(‘\n’)[1] to get specific string value.