Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Display the Requested item variables in approval notification

GChanner
Tera Guru

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);

9 REPLIES 9

Elijah Aromola
Mega Sage

You should be able to add the following where applicable. 

requestItem.variables.variable_name.getDisplayValue();

 

Please mark this as helpful if it resolved your issue.

Prateek kumar
Mega Sage

How is this even working.

current.sysapproval is not a field on sc_req_item table.


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Prateek kumar
Mega Sage

Check this out:

https://community.servicenow.com/community?id=community_question&sys_id=cb615b2ddbdcdbc01dcaf3231f96191d


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

GChanner
Tera Guru

Hi Elijah,

I added the code as show below

template.print('Summary of Requested Items: '+requestItem.variables.variable_name.getDisplayValue());

but I get a 'undefined' 

See image below

 

 

find_real_file.png