- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2021 02:14 PM
Hi All,
I have configured the variable formatter and added a Section on HR case record to show the Record producer variables submitted by employee on to the HR case as shown below .
Please help me with a requirement to include these variables under 'Case details submitted' section in the Email Notification sent to the employee when case is submitted .
I am not finding a way to call these variables in Notification , please guide.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 06:01 AM
You need to use email script for this
Name: show_variables
Script:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
template.print('Variables: <br/>');
var variables = current.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 != ''){
template.space(4);
template.print(' ' + label + " = " + value + "<br/>");
}
}
})(current, template, email, email_action, event);
Then include it in the email notification like this
${mail_script:show_variables}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2021 02:28 PM
Hi,
You can access those variables in the notification by using format like:
${variables.VARIABLE_NAME}
So if those are static variables, always there, you could write in notification:
Requested for: ${variables.requested_for}
Where "requested_for" is the name for the Requested for variable. 🙂
There are other ways too through using mail script, etc. but see if that works for you?
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2021 10:28 PM
Hi there,
Is this for a Notification which always contains the same variables? Or might the variables differ/be dynamic/etc?
If it contains the same variables:
See the answer from Allen.
If the variables differ upon situation/dynamic etc:
You could set up a mail script. Mail script which retrieves all available variables and generates a summary or similar. For example see this article which I wrote a while ago, to create a summary of variables. This is just a way to achieve it, there are multiple ways. To you could use something similar within an email script.
Generate Catalog Item Variables summary
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 05:27 AM
The variables in the Variable editor changes for each case created and we need to show the variables present on the Record in email notification.
Please let me know if this will work for Record producer variables and in Scoped application .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2021 06:01 AM
You need to use email script for this
Name: show_variables
Script:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
template.print('Variables: <br/>');
var variables = current.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 != ''){
template.space(4);
template.print(' ' + label + " = " + value + "<br/>");
}
}
})(current, template, email, email_action, event);
Then include it in the email notification like this
${mail_script:show_variables}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader