how to get most recent comment without date and who has entererd the comment

Hareesha
Tera Contributor

I have a requirement to get only the most recent comment from work notes field where we are entering the comments.

I need only comment not with date and who has entered the comment.Thanks!

4 REPLIES 4

Harshal Aditya
Mega Sage

Hi @Hareesha ,

 

Hope you are doing well.

 

Please refer below script.

var inc = new GlideRecord("incident");
inc.get("sys_id of incident");
var notes = inc.work_notes.getJournalEntry(1);
gs.log(notes);
var regex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;

gs.log(notes.replace(regex, ''));

 

Please mark this response as correct or helpful if it assisted you with your question.

Regards,
Harshal

 

Hi @Harshal Aditya ,

Thanks for your response. It not working. i am getting with date and who updated.

 

var lastcomment=current.comments.getJournalEntry(1);
var regex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
var comment=lastcomment.replace(regex, '');
template.print(comment);

 

Harshal Aditya
Mega Sage

Hi @Hareesha,

 

Thanks for your update.

I tried with the same script in my PDI it's strange it's working for me.

 

Could you please share the complete script I guess its email notification script

 

Regards,

Harshal

Hi,
I would mention to check the behavior when an incident is resolved by its related problem resolution. 

Fix notes (HTML) field is copied as a comment between [code] [/code] tags and I'm afraid that these tags will appear as comment content.  Regex should be reworked to replace that too. 

 

Best regards,