Requested Item variables in email body for approval

JaQuestt Fautne
Tera Contributor

Hey all, I know this has been asked and answered before, but I am not sure if I am implementing it wrong or something else. I am relatively new to ServiceNow scripting, I don't have much JavaScript experience at all. I have been tasked with creating an email asking for an approval on our catalog items. The email should include all the variables associated with the selected item. I have found post with mail scripts that supposedly does just that. I created a mail script using the code provided but when I call it in the email template, it does not load. Am I doing something wrong? I have attached an image of the email script, the template as well as the preview notification.

email_script.png

email_template.png

 

email_preview.png

 

 

 

1 ACCEPTED SOLUTION

ryancampbell-ud
Tera Guru

Your notification is triggered on the Approval table, so current.variables will not work in the mail script.

Try dotwalk to the RITM using sysapproval in your mail script.

 

 

 

for (var key in current.sysapproval.variables){
var v = current.sysapproval.variables[key];
template.print('\n' + v.getGlideObject().getQuestion().getLabel() + ": " + v.getDisplayValue() + " <br />");
}

 

 

View solution in original post

3 REPLIES 3

ryancampbell-ud
Tera Guru

Your notification is triggered on the Approval table, so current.variables will not work in the mail script.

Try dotwalk to the RITM using sysapproval in your mail script.

 

 

 

for (var key in current.sysapproval.variables){
var v = current.sysapproval.variables[key];
template.print('\n' + v.getGlideObject().getQuestion().getLabel() + ": " + v.getDisplayValue() + " <br />");
}

 

 

Thank you very much! This did it.

Tai Vu
Kilo Patron
Kilo Patron

Hi @JaQuestt Fautne 

Is there any MVRS in the requested item #RITM0011408? If yes, line number 7 will be empty, leading to a failure when encountering "now_V.getGlideObject().getQuestion().getLabel()".

 

Also double-check the table in the Notification as Ryan mentioned.

 

Cheers,

Tai Vu