GlideController functionality in Scoped app
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2021 09:30 AM
Currently I have an error function in a script include... I'm using in global and I want to move this process into a scoped application... I'm using GlideController to take a passed status value 430, 431 etc and use it to lookup a constant. This works fine... but how can I do this in a scoped app... the GlideScopedEvaluator() doesn't seem to work the same way.
Thanks
//this are constants at the top the SI
ERROR430/*old 415*/ = 'The following required fields are missing: ';
ERROR431/*old 416*/ = 'The following field has an incorrect value: ';
ERROR432/*old 417*/ = 'The following record was not found: ';
ERROR433/*old 419*/ = 'The following error occurred: ';
//this is the function that is called and uses those for standard output.
_errorHandle: function(status,messageAddOn,calledFunction){
var message = '';
var getErrorMessage = GlideController;
var errorConstant = 'ERROR' + status;
var errorMessageFound = getErrorMessage.evaluateString(errorConstant);
if (errorMessageFound){
message = errorMessageFound + messageAddOn;
}
else {
message = messageAddOn;
}
var cmxError = new sn_ws_err.ServiceError();
cmxError.setStatus(status);
cmxError.setMessage(message);
cmxError.setDetail("Failure in: " + calledFunction);
return cmxError;
},
- Labels:
-
Scoped App Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2021 11:35 AM
var CMX_CommonAPI = Class.create();
CMX_CommonAPI.prototype = {
STATIC_PROPERTIES: {
ERROR430:'The following required fields are missing: ',
ERROR431:'The following field has an incorrect value: ',
ERROR432:'The following record was not found: ',
ERROR433:'The following error occurred: ',
},
initialize: function() {
ERROR_FOUND = '';
},
_errorHandle: function(status,messageAddOn,calledFunction){
var message = '';
//var getErrorMessage = GlideScopedEvaluator;
var errorConstant = 'ERROR' + status;
var errorMessageFound = this.STATIC_PROPERTIES[errorConstant];
if (errorMessageFound){
message = errorMessageFound + messageAddOn;
}
else {
message = messageAddOn;
}
var cmxError = new sn_ws_err.ServiceError();
cmxError.setStatus(status);
cmxError.setMessage(message);
cmxError.setDetail("Failure in: " + calledFunction);
return cmxError;
},
This is what's returned from when that runs for me... in a scoped application rest api
{
"error": {
"detail": "TypeError: Cannot read property \"ERROR430\" from undefined (sys_script_include.0f7861a4db1a2c50de4bc139139619c1.script; line 20)",
"message": "Cannot read property \"ERROR430\" from undefined"
},
"status": "failure"
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2021 11:39 AM
What I updated to using an array did work however

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2021 11:42 AM
Must be something wrong in your code somewhere. Just called the script include from a Scripted REST API and this is what I got:
{
"error": {
"detail": "Failure in: myFunction",
"message": "The following required fields are missing: my_field"
},
"status": "failure"
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2021 11:48 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2021 11:57 AM
Unexplainable. I would just double check that you had everything saved and any other code that could be interfering because it's working perfectly on my instance and this is standard Javascript, no special ServiceNow stuff going on here.