logo

NJP

Accessing Global REST Messages within a scoped application

Import · Apr 14, 2016 · article

If you happen to run into the following error within a scoped application: Error constructing REST Message/Method: The chances are you need to dereference the global namespace for your REST Message name.

Here are the symptoms of this behavior. You create a REST Message in global scope that is accessible to all Application Scopes. You test it using the Test Related Link.

image

It returns a beautiful 200 HTTP Status Code. You use the Preview Script Usage and copy the contents to use within a scoped application. It doesn't work. You get the Error constructing REST Message/Method:.

You need to prefix your REST Message name with global (like so):

try {

var r = new sn_ws.RESTMessageV2('global.rest_message_name', 'get');

var response = r.execute();

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

}

catch(ex) {

var message = ex.getMessage();

}

View original source

https://www.servicenow.com/community/developer-blog/accessing-global-rest-messages-within-a-scoped-application/ba-p/2289650