How To get the comment which is provided while rejecting approval( not all comments )?

lp6
Tera Guru

I want to get the rejected comment only as the subject line but not all comments 

1 ACCEPTED SOLUTION

you need to remove that timestamp like this

var value = current.comments.getJournalEntry(1);

var str = value.split(' - ')[1];

var name = str.split(') ')[0] + ')';

var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;

gs.info(name);

var onlyComments = value.replace(dateRE, '');

template.print('Rejection comments' + onlyComments);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

@lp 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers..!

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@lp 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers..!

Regards
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Mahesh23
Mega Sage

Hi,

Try the below code

var latestComments = current.comments.getJournalEntry(1):
// In my case journal entry looks like this "2022-02-21 System Administrator (Additional Comments) request has been rejected"
var splitComments = latestComments.split('(Additional Comments)'); 
var getComments = splitComments[1]; // request has been rejected 
template.print(getComments);