- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2025 06:27 AM - edited 08-05-2025 02:25 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2025 07:09 AM
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);
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;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2025 06:41 AM
Hi @sath
I think it is OOTB available.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2025 07:09 AM
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);
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;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2025 10:37 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2025 11:14 AM - edited 08-06-2025 11:15 AM
Hi @Ankur Bawiskar Sorry for the delay, the above script worked when I ran it on background scripts. How can we check this in real time on sub prod instances?
We have a test email box where all the emails from our sub prod instances will be sent to. I have enabled inbound emails on our dev instance and triggered approval email and input the comments, but the email says it is undeliverable.