- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2023 12:51 PM
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.
 
 
 
 
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2023 08:43 PM - edited ‎11-27-2023 08:45 PM
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 />");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2023 08:43 PM - edited ‎11-27-2023 08:45 PM
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 />");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2023 06:04 AM
Thank you very much! This did it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-27-2023 08:48 PM - edited ‎11-27-2023 08:51 PM
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