Display the Requested item variables in approval notification

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2019 12:59 PM
We have a notification which uses a 'email script' to notify approvers of a Request awaiting their approval. The problem is other than the requested item name, short description & description the notification does not tell the approver what variables where selected by the submitter.
How can I include the variables in my email script below?
==== current script =====
(function runMailScript(current, template, email, email_action, event) {
var requestItem = new GlideRecord('sc_req_item');
requestItem.addQuery('sys_id',current.sysapproval);
requestItem.query();
if(requestItem.next())
{
var subject = 'Item: '+requestItem.cat_item.name+' for '+requestItem.request.requested_for.getDisplayValue()+' is waiting for your approval';
email.setSubject(subject);
template.print('Dear '+current.approver.getDisplayValue());
template.print('<br/>');
template.print(requestItem.cat_item.name+' is waiting for your approval');
template.print('<br/>');
template.print('Requested For: '+requestItem.request.requested_for.getDisplayValue());
template.print('<br/>');
template.print('Opened by: '+requestItem.opened_by.getDisplayValue());
template.print('<br/>');
template.print('RITM: '+requestItem.number.getDisplayValue());
template.print('<br/>');
template.print('Requested Item: '+requestItem.cat_item.name);
template.print('<br/>');
template.print('Approval Manager: '+current.approver.getDisplayValue());
template.print('<br/>');
template.print('State: '+current.state);
template.print('<br/>');
//template.print('<br/>');
//template.print('Comments: '+current.comments);
}
})(current, template, email, email_action, event);
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2019 07:06 PM
Hi,
Please refer the below blogs for your query:
1) For displaying Variable info in Notification when the Target table is in Global Scope:
https://community.servicenow.com/community?id=community_blog&sys_id=ee8519acdb00bfc42be0a851ca961921
2) For displaying Variable info in Notification when the Target table is in Custom Scope:
Hope this helps.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-26-2019 11:56 AM
Thank you Shloke04
Your suggestion at https://community.servicenow.com/community?id=community_blog&sys_id=ee8519acdb00bfc42be0a851ca961921 worked great
How can I increase the spacing between words and the table? See screen shot. I used arrows to indicate where I need spacing
========This is the mail script =========
var table = current.getTableName();
var count = 0;
if (table == 'sysapproval_approver') {
count = 1;
} else {
for(vars in current.variable_pool){
count++;
break;
}
}
template.print('Dear '+current.approver.getDisplayValue());
template.print('<br/>');
template.print('Item: '+current.sysapproval.cat_item.name.getDisplayValue()); template.print('is waiting for your approval');
template.print('<br/>');
template.print(''+current.document_id.getDisplayValue());
template.print('<br/>');
template.print('Opened by: '+current.sysapproval.opened_by.getDisplayValue());
template.print('<br/>');
template.print('Requested For: '+current.u_mhs_requested_for.getDisplayValue());
template.print('<br/>');
template.print('Approval Manager: '+current.approver.getDisplayValue());
template.print('<br/>');
template.print('State: '+current.state);
template.print('<br/>');
template.print('<br/>');
template.print('Below is a summary of what is being requested: ');
template.print('<br/>');
if(count > 0){
var mvalue = '';
var list = [];
var display = [];
template.print('<table border="1">');
//Query for the non-empty variables for this record
//Catalog item and task variables pull from 'sc_item_option_mtom' table
if(table == 'sc_req_item' || table == 'sc_task' || table == 'sysapproval_approver') {
var itemVars = new GlideRecord('sc_item_option_mtom');
if(table == 'sc_req_item'){
itemVars.addQuery('request_item', current.sys_id);
}
if(table == 'sc_task'){
itemVars.addQuery('request_item', current.request_item.sys_id);
}
if(table == 'sysapproval_approver'){
itemVars.addQuery('request_item', current.sysapproval.sys_id);
}
itemVars.addNotNullQuery('sc_item_option.value');
//Exclude Label and Container variables
itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 11);
itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 19);
itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 20);
itemVars.addQuery('sc_item_option.item_option_new.type', '!=', 24);
itemVars.orderBy('sc_item_option.order');
itemVars.query();
while(itemVars.next()){
template.print("<tr>");
template.print("<td>"+itemVars.sc_item_option.item_option_new.question_text+"</td>");
mvalue = itemVars.sc_item_option.value;
// Check if the value is from the reference field
if (itemVars.sc_item_option.item_option_new.type == '8') {
var grRefTable = new GlideRecord(itemVars.sc_item_option.item_option_new.reference);
grRefTable.addQuery('sys_id',mvalue);
grRefTable.query();
if (grRefTable.next()) {
mvalue = grRefTable.getDisplayValue();
}
template.print("<td>"+mvalue+"</td>");
template.print("</tr>");
}
// Check if the type is List Collector
if(itemVars.sc_item_option.item_option_new.type == '21') {
list = itemVars.sc_item_option.value.split(',');
for(var i=0; i<list.length; i++){
var grListTable = new GlideRecord(itemVars.sc_item_option.item_option_new.list_table);
grListTable.addQuery('sys_id',list[i]);
grListTable.query();
if (grListTable.next()) {
display.push(grListTable.getDisplayValue());
}
}
template.print("<td>"+display+"</td>");
template.print("</tr>");
}
// Check if the type is Select Box
if(itemVars.sc_item_option.item_option_new.type == '5') {
var grQuestion = new GlideRecord('question_choice');
grQuestion.addQuery('question', itemVars.sc_item_option.item_option_new);
grQuestion.addQuery('value', itemVars.sc_item_option.value.toString());
grQuestion.query();
if(grQuestion.next()){
mvalue = grQuestion.getValue('text');
}
template.print("<td>"+mvalue+"</td>");
template.print("</tr>");
}
//For rest of the types
if(itemVars.sc_item_option.item_option_new.type != '21' && itemVars.sc_item_option.item_option_new.type != '8' && itemVars.sc_item_option.item_option_new.type != '5' )
{
template.print("<td>"+mvalue+"</td>");
template.print("</tr>");
}
}
}
template.print("</table>");
}
====== This is the Generated Message ==========
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2023 08:45 AM
I am not sure if this was completely answered, but now there is an out-of-box Notification that includes most of these details and uses the "pretty" layout too, it just comes inactive:
"Requested item approval assigned" actually looks quite nice right out of the box, just make sure you configure your triggers as this one only fires for RITM approvals, so those would need to be excluded from your "default" approval email.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 06:51 AM
I found that new 'pretty' notification, and it suits my business requirements allllmost perfectly. I have worked with several others already, and we need whatever value is in the description field of the RITM (that's being approved) pulled over, and added under the line for "Short Description". Seems fairly straightforward, but I'm still struggling to get the value pulled over, and all I get is "undefined".
I simply copied line 35 from the current mail script "request_item_approval" :
but swapped it to say "Description:" and instead of "requestItemDetails.item" I did "requestItemDetails.description". I simply need whatever is in the description field brought over as well as the short description, and then still all the RITM variables underneath (and that part is working fine). Any ideas what I'm doing wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 03:09 PM
Hey @Stephanie Barne it looks like the object "requestItemDetails" is actually not a glide record, but an object generated on line 24 from a Client Script called global.RequestNotificationUtil() from a method called "getRequestItemDetails". That Client Script is the configurable one from the oob one called global.RequestNotificationUtilSNC.
Unfortunately, this Script Include does not consider capturing nor sending back the "description" as part of the object.
But you really don't need to use that, as you have the "current" object for the approval record and you can use a script line similar to 20 and 21:
request.requested_for = current.sysapproval.request.requested_for;
request.opened_by = current.sysapproval.request.opened_by;
template.print('<div style="' + fontSize + lineHeight + '">Description: <b style="font-weight: 600;">' + current.sysapproval.description + '</b></div>');
Try that and let me know if it works,
WS