Unable to get my notification email script to work in my custom application.

Ty9
Kilo Contributor

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

1 ACCEPTED SOLUTION

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

https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

 

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.

 

View solution in original post

6 REPLIES 6

Tim Deniston
Mega Sage
Mega Sage

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. 

RatneshTSN
Giga Guru

Hi,

 

If its not solve, can you post in detail; it would help to answer your queries.

Ty9
Kilo Contributor

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

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

https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

 

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.