- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2020 11:15 AM
Hi,
I have one catalog item named as xyz which contains workflow name as yz. When user raised a request it will be go for the user's manager approval. In the approval email few fields are need to visible.
Approval email is sending for sysapprover table. Could anyone please help on this.
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2020 08:24 AM
Hi,
I didn't get.
Since user has filled 10 variables those 10 will come in email.
Why to display only 5 variables? are you saying you want to keep specific variables only and exclude some 5?
if yes then try this
ensure you give valid variable names in the if condition
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
template.print('Summary of requested item: <br/>');
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', current.sysapproval);
ritm.query();
if(ritm.next()){
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();
var name = question.getName();
if(name != 'variable1' && name != 'variable2' && name != 'variable3' && name != 'variable4' && name != 'variable5'){
if(label != '' && value != ''){
template.space(4);
template.print(' ' + label + " = " + value + "<br/>");
}
}
}
}
})(current, template, email, email_action, event);
})(current, template, email, email_action, event);
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
11-09-2020 11:25 AM
Hi Arun,
You can have a mail script named: getrequiredvariables with code as below.
(function runMailScript(current, template, email, email_action, event) {
template.print("<b>Summary of Requested items:\n</b>");
var getvariables=new GlideRecord('sc_req_item');
getvariables.addQuery('sys_id',current.sysapproval);
getvariables.query();
while(getvariables.next())
{
template.print('Var 1 '+getvariables.variable_name1);//replace variable name
template.print('Var 2 '+getvariables.variable_name2); //replace variable name
}
}
Call mail script in notification body of Approval table notification in format
${mail_script:getrequiredvariables}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2020 06:25 AM
Hi,
It is not working for the reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2020 06:58 AM
Hi Arun,
Can you please check my comment and script shared
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
11-10-2020 09:32 AM
Hi Arun,
It is not working as the syntax has an issue. Line below was missed as it should be last line.
})(current, template, email, email_action, event);
In other words, you need to use below.
(function runMailScript(current, template, email, email_action, event) {
template.print("<b>Summary of Requested items:\n</b>");
var getvariables=new GlideRecord('sc_req_item');
getvariables.addQuery('sys_id',current.sysapproval);
getvariables.query();
while(getvariables.next())
{
template.print('Var 1 '+getvariables.variable_name1);//replace variable name
template.print('Var 2 '+getvariables.variable_name2); //replace variable name
}
})(current, template, email, email_action, event);