- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
How to pull all related field values of "Requested Item Summary" of a sysapproval_approver record to a notification body using Email template in Servicenow?
Please see attached and advise if you've any idea!?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hey @sharsha
Try this :
Step 1: Create a Notification Email Script
Create a new Email Script (for example, RITM_Variable_Summary)
code:
(function runMailScript(current, template, email, email_action, event) {
var ritm = current.sysapproval.getRefRecord();
if (!ritm || !ritm.isValidRecord())
return;
template.print("<h3>Requested Item Summary</h3>");
template.print("<table border='1' cellpadding='5' cellspacing='0' style='border-collapse:collapse;width:100%;'>");
template.print("<tr style='background:#f2f2f2;'>");
template.print("<th align='left'>Question</th>");
template.print("<th align='left'>Response</th>");
template.print("</tr>");
var variables = ritm.variables.getElements();
for (var i = 0; i < variables.length; i++) {
var variable = variables[i];
template.print("<tr>");
template.print("<td>" + variable.getQuestion().getLabel() + "</td>");
template.print("<td>" + variable.getDisplayValue() + "</td>");
template.print("</tr>");
}
template.print("</table>");
})(current, template, email, email_action, event);Step 2: Call the Mail Script in the Notification
In your Approval Notification (Table: sysapproval_approver), add the following to the Message HTML:
Requested Item Summary
${mail_script:RITM_Variable_Summary}*********************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
You need to use email script in your email body and include it in email
Mail script: print_cat_item_request_submitted
Script
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
template.print('Requested Item Summary: <br/>');
var ritm = new GlideRecord('sc_req_item');
ritm.get('request', current.sysapproval);
var variables = ritm.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if(label != '' && value !=''){
template.space(4);
template.print(' ' + label + " = " + value + "<br/>");
}
}
})(current, template, email, email_action, event);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @sharsha
To retrieve the fields and variables of a Requested Item (RITM) from a sysapproval_approver record in an email notification, use an Email Script.
Note: Standard dot-walking (for example, ${sysapproval.variable_name}) does not reliably display catalog variables, especially multi-line variables or complete variable summaries.
You can try this sample email script.
1: Create an Email Script
Navigate to System Policy > Email > Notification Email Scripts and create a new script.
- Name: ritm_summary_details
(function runMailScript(current, template, email, email_action, event) {
var ritmSysId = current.getValue('sysapproval');
if (ritmSysId) {
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(ritmSysId)) {
template.print('<h3>Requested Item Summary</h3>');
template.print('<b>Item:</b> ' + ritmGR.cat_item.getDisplayValue() + '<br />');
template.print('<b>Item Number:</b> ' + ritmGR.getValue('number') + '<br />');
template.print('<b>Quantity:</b> ' + ritmGR.getValue('quantity') + '<br />');
template.print('<b>Short Description:</b> ' + ritmGR.getValue('short_description') + '<br /><br />');
template.print('<b>Options / Variables Selected:</b><br />');
var variables = ritmGR.variables;
for (var keyRitm in variables) {
var varRitm = variables[keyRitm];
if (varRitm.getGlideObject().getQuestion().getLabel() != '' && varRitm.getDisplayValue() != '') {
template.print(' • ' + varRitm.getGlideObject().getQuestion().getLabel() + ': ' + varRitm.getDisplayValue() + '<br />');
}
}
}
}
})(current, template, email, email_action, event);
2: Call the Script in Your Email Body/Template
- Open the targeted Email Template or Notification record configured on the sysapproval_approver table.
- Insert the script call inside the Message HTML body
Dear ${approver},
An approval request has been generated for your review.
${mail_script:ritm_summary_details}
Click here to view the approval: ${URI_REF}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @sharsha ,
Is the requested item summary same as what the requestor has filled while submitting the form. If yes then it's pretty simple. You can do a Glide record query on sc_req_item table with filter as current.number(RITM number). Then u can access those variables like gr.variables.requestor. this way u can populate whatever u want in the notification body.
Thanks,
Danish Bhairagdar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Yes @Danish Bhairag2 , 'Requested item summary' is what the requestor has filled while submitting the catalog item form in the ESC portal. Could you please help me in detail please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @sharsha ,
Please refer the comments from either @Ankur Bawiskar / @vaishali231 that should help you.
Thanks,
Danish Bhairagdar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Yes @Danish Bhairag2 , 'Requested item summary' is what the requestor has filled while submitting the catalog item form in the ESC portal. Could you please help me in detail please, how to configure this with the help of notifications?