Error message while using ECC Queue

bradwestvig
Giga Guru

I've been looking to leverage the ECC Queue to queue up messages for some REST calls.  I'm able to call my REST call when specifying the parameters in the script.

 

	var request = new sn_ws.RESTMessageV2();
	
	var sendTicketStatusEndPoint = 'https://test';
	var password = 'admin';
	var userId = 'admin';
	
	gs.log("URL "+sendTicketStatusEndPoint);
	
	request.setEndpoint(sendTicketStatusEndPoint);
	request.setHttpMethod('POST');
	
	request.setBasicAuth(userId,password);
	request.setQueryParameter("sys_id",current.sys_id);
	request.setLogLevel('all');
	var response = request.execute();

But when I try to use the ECC Queue

var r = new sn_ws.RESTMessageV2('XXXX', 'POST');

 r.setQueryParameter("sid",current.sys_id);
 r.setRequestBodyFromAttachment("");
 var response = r.executeAsync();
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();

I'm able to Test my message from the REST Setup and I get a successful response from the API.

But when I execute the code from a background script or BR it doesn't work.  This is the error message I get.

<?xml version="1.0" encoding="UTF-8"?><results error="Error invoking http request: Error executing REST request: attachment does not exist with sys_id: undefined"><parameters><parameter name="http_status_code" value="500"/></parameters></results>

 

Any ideas why it works when you run a test in the REST Message?

find_real_file.png

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Brad,

 

This is because for the following code when it runs in background script current.sys_id doesn't make any sense:

If you want to run from background script give hardcoded sys id and check

 

var r = new sn_ws.RESTMessageV2('XXXX', 'POST');

r.setQueryParameter("sid",current.sys_id);

r.setRequestBodyFromAttachment("");

var response = r.executeAsync();

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

 

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

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

Trevor Muhl
Kilo Sage

Hello,

I encountered this error myself and managed to discover a workaround.

Looking at your code, it appears that you are not setting any request body content. If true, this is the same scenario I was in.

I believe this error is caused by a null request body. The error message implies that the asynchronous REST message saves the request body as an attachment to the "Schedule" (sys_trigger) record. When the request body is null, the attachment is not created. Therefore, when the request is executed later, it is not able to find the expected attachment. The request then fails.

To fix this, simply set an empty request body: "{}". When using a REST message function, it might look like the following:

find_real_file.png

I hope this helps! Let me know if you have any questions about this.

- Trevor Muhl

Thanks!

Thanks. Its working.