How do I summarise a change request in a request approval email notification?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 07:06 PM
Hi,
I have created a request approval email notification for a change request. My goal is to include a summary of the change request in this email. I would ideally like it to be similar to how it is summarised on the approval request with the out of the box summariser. This displays the view 'approval'.
The problem I am encountering (other than my lack of scripting super powers!) is that from reading I have discovered the out of the box change_request_summary email script seems to only print variables when a change request is created from a record producer.
This leaves me with a gap I am hoping you can help with!
If anyone has any useful information or guidance on how to begin putting this together as a mail script, aligned with best practice, that would be fantastic.
Thanks in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 08:26 PM
Did you try this?
var set = new GlideappVariablePoolQuestionSet();
set.setTaskID(current.getValue('sysapproval'));
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '') {
template.print(' ' + vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 09:12 PM
I see an example documented for Request Items : Scripting for Email Notifications - ServiceNow Wiki.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 08:59 PM
The general approach I take for email notification is to just generate them in an email script. It's the easiest way to get the style and content you want.
You call a mail script from the Message HTML field like this:
Then you create an Email Script with the name you specified.
I like to make then easily maintainable by creating convenience functions for easily adding whatever fields you like.
(function runMailScript(current, template, email, email_action, event) {
// Functions for adding new fields
function addField(fieldName) {
template.print('<tr><td><b>' + current[fieldName].getLabel() + '</b></td><td>' + current[fieldName].getDisplayValue() + '</td></tr>');
}
function addLargeField(fieldName) {
template.print('<tr><td colspan="2"><b>' + current[fieldName].getLabel() + '</b></td></tr>');
template.print('<tr><td colspan="2">' + current[fieldName].getDisplayValue() + '</td></tr>');
}
function addVariable(variableName) {
template.print('<tr><td><b>' + current.variables[variableName].getLabel() + '</b></td><td>' + current.variables[variableName].getDisplayValue() + '</td></tr>');
}
// Email content
template.print('<p>Some intro paragraph</p>');
template.print('<table>'); // Start of fields output
addField('opened_by');
addField('type');
addField('short_description');
addLargeField('description');
addVariable('varaible1');
addVariable('varaible2');
addVariable('varaible3');
template.print('</table>');
})(current, template, email, email_action, event);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2019 05:05 AM
Brilliant!!
I had to quickly learn how to set the font to make sure it fits in with our templates but this works a treat and made a demanding customer very happy:
(function runMailScript(current, template, email, email_action, event) {
// Functions for adding new fields
function addField(fieldName) {
template.print('<tr><td><b><font size="2" face="arial">' + current[fieldName].getLabel() + '</b></td><td><font size="2" face="arial">' + current[fieldName].getDisplayValue() + '</td></tr>');
}
function addLargeField(fieldName) {
template.print('<tr><td colspan="2"><b><font size="2" face="arial">' + current[fieldName].getLabel() + '</b></td></tr>');
template.print('<tr><td colspan="2"><font size="2" face="arial">' + current[fieldName].getDisplayValue() + '</td></tr>');
}
function addVariable(variableName) {
template.print('<tr><td><b><font size="2" face="arial">' + current.variables[variableName].getLabel() + '</b></td><td>' + current.variables[variableName].getDisplayValue() + '</td></tr>');
}
// Email content
template.print('<p><b>Summary of Change</b></p>');
template.print('<table>'); // Start of fields output
addField('opened_by');
addField('type');
addLargeField('short_description');
addLargeField('description');
//addVariable('varaible1');
//addVariable('varaible2');
//addVariable('varaible3');
template.print('</table>');
})(current, template, email, email_action, event);
I will be using this again for other notifications.
Regards,