Workflow runscript activity failing with error:- Error MessageInvalid object in scoped script: org.mozilla.javascript.NativeJavaObject@5005785

Suneel9
Tera Contributor

I recently started learning ServicenNow and trying to develop Service Catalog item for users to request.

Appreciate your help in finding the fault in the code.

Version: Kingston

Application: scoped application ( Service Catalog Item & Workflow for the SC item)

I have the following code in a run script activity (AddTargetToInventory). The code will make a REST API call to third party application.

===================================================================================

gs.info("Hello from 00 of AddTargetToInventory!!") ;

try {
 var mid_server =   gs.getProperty('x_abcd_sense_and_r.DEV-MID') ;
 gs.info("Hello from 01 of AddTargetToInventory!!") ;
 var rest_m = new sn_ws.RESTMessageV2('ManageTargetInventory', 'AddHostToTargetInventory') ;
 gs.info("Hello from 02 of AddTargetToInventory!!") ;
 rest_m.setStringParameterNoEscape('name', workflow.scratchpad.serverName) ;
 rest_m.setRequestHeader("Accept","Application/json");
 rest_m.setRequestHeader("Authorization", "Basic c2dhbGk6j0FuZGhyYScwMDcn") ;
 rest_m.setMIDServer(mid_server) ;
 rest_m.setHttpTimeout(10000) ;
 rest_m.setEccParameter('skip_sensor', true) ;
 gs.info("Hello from 03 of AddTargetToInventory!!") ;    
 var response = rest_m.execute() ;
 var responseBody = response.getBody() ;
 var httpStatus = response.getStatusCode() ;
 gs.info("Hello from 04 of AddTargetToInventory!!") ;
 var parsedTemplateExecResponseBody    = global.JSON.parse(responseBody) ;
 
 gs.info("Hello from 05 of AddTargetToInventory!!") ;
 workflow.scratchpad.jobTemplateExecStatus = httpStatus ;
 workflow.scratchpad.returnedJobID = parsedTemplateExecResponseBody.job ;
}
catch(ex) {
 var message = ex.getMessage();
 gs.info("ERROR:- {0}", message) ;
}

===========================================================================

 

In the workflow log I see the following entry from the script

 

13:52:44.885InfoDefault-thread-10140E52BBDB6F7F84069B90D8DB961984txid=9a5b43bfdb6f x_baom_sense_and_r: Hello from 03 of AddTargetToInventory!!

 

As the next expected entry is not in the log, I think the code is failing between (mostly execute()):

gs.info("Hello from 03 of AddTargetToInventory!!") ;    
 var response = rest_m.execute() ;
 var responseBody = response.getBody() ;
 var httpStatus = response.getStatusCode() ;
 gs.info("Hello from 04 of AddTargetToInventory!!") ;

I am getting the following error message:

Error Message Invalid object in scoped script: org.mozilla.javascript.NativeJavaObject@<some number>

 

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Suneel,

when you use Mid Server with Outbound RESTMessage you need to wait for few time to get the response since mid server will communicate to API

then try to print the responseBody

// In seconds. Wait at most 60 seconds to get response from ECC Queue/Mid Server
response.waitForResponse(60);

var responseBody = response.getBody() ;
var httpStatus = response.getStatusCode() ;
gs.info("Hello from 04 of AddTargetToInventory!!") ;

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Suneel9
Tera Contributor

Thanks Ankur. I will try that but I think the REST call itself is not reaching the endpoint as I am not seeing any activity on the endpoint.

Suneel9
Tera Contributor

I added the wait time and still getting the same error message.

Hi Suneel,

what you are seeing in ecc_queue since you are using mid server?

what message you are getting in catch exception?

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader