How to call REST Message via Scheduled Job in scoped application?

yogeshmore
Kilo Explorer

Hi,

I have tried using following code in my Scheduled Job (SJ) to call REST Message in a scoped application.

var r = new sn_ws.RESTMessageV2('x_snc_all_time_car.All Surf SN TimeCard', 'get');

var response = r.execute();

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

var parser = new JSONParser();

var parsed = parser.parse(responseBody);

It gives a warning and SJ doesn't get executed at all:

java.lang.SecurityException: JSONParser undefined, maybe missing global qualifier

Then I tried amending with global as below:

var r = new sn_ws.RESTMessageV2('x_snc_all_time_car.All Surf SN TimeCard', 'get');

var response = r.execute();

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

var parser = new global.JSONParser();

var parsed = parser.parse(responseBody);

It gives a warning and SJ doesn't get executed at all:

org.mozilla.javascript.EcmaError: The undefined value has no properties.


Anyone have any idea to handle with this?


Thanks,

Yogesh More

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Yogesh,



Please follow the below steps and let me know the outcome.


Go to the script include->Search for JSONParser->Now make sure the field "accessible from" is set to "All application scopes". OOB this is set to be "this application scope only".


Please find the screenshot attached for reference.


Screen Shot 2015-06-06 at 7.40.51 PM.JPG



View solution in original post

8 REPLIES 8

Thanks Yogesh


Glad to know your issue is resolved.


Hello.



I have a similar issue when a script in the workflow for my scoped application calls the JSONParser. Note the same script was working fine when it was in global scope. The error seen in the logs is:



JSONParser undefined, maybe missing global qualifier



I tried adding the following lines at the top of the script, but I still get the error:


gs.include("global.JSON");


gs.include("global.JSONParser");



var parser = new JSONParser();


var parsed = parser.parse(activityOutput); ---> Error thrown here


Try var parser = new global.JSONParser();


silas1
ServiceNow Employee
ServiceNow Employee

Looks like this worked for the OP and should work for you too:




gs.include("global.JSON");


var json = new global.JSON();


var parsed = json.decode(responseBody);