How to enter only comments from approval email

sath
Tera Expert

Hi,

 

When an approver is approving via email, the below should be sent to them:

 

"If you would like to enter comments, place them between the starred lines below, then click Send:

******************************************************************************

(comment entered by approver)

****************************************************************************** "

When the email is received, the comments entered by the approver should be written to the approval record, just the comment itself (and not the surrounding text) should be written to the approval record.

 

We can update the content on email templates (mailto.rejection and mailto.approval), but not sure how to remove surrounding content, can you please assist?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@sath 

for removing the surrounded content, you will have to update the OOTB inbound action and use string manipulation to extract the comments

Something like this worked for me, so please enhance as per your requirement

// Simulated email body with instructional text and approver comment
var emailBody = "If you would like to enter comments, place them between the starred lines below, then click Send:\n" +
"******************************************************************************\n" +
"This is the comment entered by the approver.\n" +
"Please review carefully.\n" +
"******************************************************************************\n" +
"Additional trailing text or signature";

// Regex to capture content between 78 or more stars (asterisks)
var regex = /[*]{78,}\s*([\s\S]*?)\s*[*]{78,}/m;

// Extract the comment
var match = regex.exec(emailBody);
var comment = "";
if (match && match[1]) {
    comment = match[1].trim();
}

// Output the extracted comment for confirmation
gs.info("Extracted comment:\n" + comment);

AnkurBawiskar_1-1754316484588.png

You can update like this

var body = email.body_text;
    var comment = '';
    var re = /[*]{78,}\s*([\s\S]*?)\s*[*]{78,}/m; // Match 78+ stars and capture what’s between

    var match = re.exec(body);
    if (match && match[1]) {
        comment = match[1].trim();
    }

    // Set the comment on the approval record (example for a task approval)
    current.comments = comment;

AnkurBawiskar_2-1754316537286.png

 

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

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

View solution in original post

9 REPLIES 9

@sath 

Glad to know that script worked.

To test you will have to use DEV instance and enable incoming email.

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

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

@Ankur Bawiskar Yes, I have enabled incoming email from email properties but it says that the delivery has failed. Checking if there is anything else that needs to be configured?

@sath 

in your DEV when you enabled incoming email, you need to enable sending also

1) send email for approval and let it come to your email address (the approver to whom approval is requested, in his/her profile add your email address OR make yourself as the approver)

2) add your email address in this field so that emails come only to your mail box and not for others

AnkurBawiskar_0-1754572987816.png

 

3) then reply to that email with that string which you added in question

4) check the inbound action triggered or not and then processed or not, add some logs and then verify if the content was extracted or not.

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

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

@Ankur Bawiskar 

We have outgoing email enabled to a test mail box and can see approval emails over there. After inputting the approval comments on email and sending it back to ServiceNow, it is getting failed.

 

Screenshot 2025-08-07 at 11.21.17 AM.png

@sath 

email is not coming to ServiceNow?
If yes then it's another issue and nothing to do with inbound action.

your inbound action will run when email comes to instance.

May be there are some email filters in your instance which are blocking the incoming email, please check that

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

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