- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 05:09 PM
I have a notification email script that works great in the Global application. I'm unable to get it in my custom application though. The email script adds and displays all variables from a record producer within a sent email. Below are things I have tried and more details I discovered while troubleshooting:
- I created a copy of the working email script and put it in the custom application
- The record producer is in the custom application
- The record producer variable are in the custom application
- The email notifications are in the custom application
Any help would be appreciated.
Thanks.
Ty
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2018 08:37 PM
As warning says, its scoped application in which getGlideObject can't be used, try reading in servicenow docs of alternative methods.
You are using method of GlideElement - Global methods in scope application
To use => GlideElement - Scoped methods
If you need to print variable name & its value.
You can simply print 'key' variable label & for value like
for (var key in current.variables) {
template.print('<p><font size="3" face="arial">');
template.print("<div><b>" + key + "</b>: " + current.variables[key] + "</div>\r\n");
}
Just in-case if all good & emails are not getting sent, you may need to just pass email id in this
email.setFrom("Facilities Help Desk <facilities.helpdesk@terumobct.com>");
email.setFrom("facilities.helpdesk@terumobct.com");
Mark this answer helpful, if it solves, if not let me know happy to help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 05:18 PM
Are you receiving any errors in the logs when this runs? Are you sure it's trying to run?
Can you post the script itself? There are some differences between scoped vs. non-scoped API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2018 07:46 PM
Hi,
If its not solve, can you post in detail; it would help to answer your queries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2018 09:47 AM
Hi,
I checked the System log. I get two warnings when I run the notification email script in the custom application:
Warning #1
Level: Warning
Source: Evaluator
Message:
com.glide.script.fencing.MethodNotAllowedException: Function getGlideObject is not allowed in scope x_tebc2_fac_manage
Caused by error in <refname> at line 1
==> 1: (function runMailScript(current, template, email, email_action, event) {
2:
3: // Add your code here
4: email.setFrom("Facilities Help Desk <facilities.helpdesk@terumobct.com>");
Warning #2
Level: Warning
Source: Evaluator
Message:
com.glide.script.fencing.MethodNotAllowedException: Function getGlideObject is not allowed in scope x_tebc2_fac_manage
Caused by error in Email Script: 'fac_from' at line 8
5: for (var key in current.variables) {
6:
7: template.print('<p><font size="3" face="arial">');
==> 8: template.print("<div><b>" + current.variables[key].getGlideObject().getQuestion().getLabel() + "</b>: " + current.variables[key].getDisplayValue() + "</div>\r\n");
9: }
10:
11: })(current, template, email, email_action, event);
Here is the notification email script:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
email.setFrom("Facilities Help Desk <facilities.helpdesk@terumobct.com>");
for (var key in current.variables) {
template.print('<p><font size="3" face="arial">');
template.print("<div><b>" + current.variables[key].getGlideObject().getQuestion().getLabel() + "</b>: " + current.variables[key].getDisplayValue() + "</div>\r\n");
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2018 08:37 PM
As warning says, its scoped application in which getGlideObject can't be used, try reading in servicenow docs of alternative methods.
You are using method of GlideElement - Global methods in scope application
To use => GlideElement - Scoped methods
If you need to print variable name & its value.
You can simply print 'key' variable label & for value like
for (var key in current.variables) {
template.print('<p><font size="3" face="arial">');
template.print("<div><b>" + key + "</b>: " + current.variables[key] + "</div>\r\n");
}
Just in-case if all good & emails are not getting sent, you may need to just pass email id in this
email.setFrom("Facilities Help Desk <facilities.helpdesk@terumobct.com>");
email.setFrom("facilities.helpdesk@terumobct.com");
Mark this answer helpful, if it solves, if not let me know happy to help you.