Running a Rest message from scheduled job

Neha Agarwal
Giga Expert

I have a rest message with POST method, rest message is running and giving result in test run. but when I am trying to run this using scheduled job it gives me error.

I wrote this:

var r = new sn_ws.RESTMessageV2('RestMessage','post');

var response = r.execute();

var responseBody = response.getBody();

var httpStatus = response.getStatusCode();

var parser = new global.JSONParser();

var parsed = parser.parse(responseBody);

I get the error:

REST Msg Outbound - RESTMessageClient : Error constructing REST Message/Method: global.legalholdpro/post: com.glide.generators.InvalidGlideRecordException: REST message/method 'global.legalholdpro/post' not found in table 'sys_rest_message_fn': com.glide.rest.outbound.RESTMessageDAO.getMethodRecord(RESTMessageDAO.java:97)
com.glide.rest.outbound.RESTMessageDAO.<init>(RESTMessageDAO.java:72)
com.glide.rest.outbound.RESTMessageDAO.newInstance(RESTMessageDAO.java:67)

also I need to push the results which is in JSON format in a staging form, which will work after rest gets executed. Please suggest?

 

1 ACCEPTED SOLUTION

This worked for me:

 

var Url = 'https://www.testurl.com/';

var request = new sn_ws.RESTMessageV2();

request.setHttpMethod('post');

request.setEndpoint(Url);

request.setRequestHeader("Content-type",'application/json');

request.setRequestHeader("Authorization",'Bearer YYNp0IIJozbzfUV9');

var response = request.execute();

var httpResponseStatus = response.getStatusCode();

var httpResponseContentType = response.getHeader('Content-Type');

//Debug the results:

gs.debug("http response status_code: " + httpResponseStatus);

gs.debug("http response content-type: " + httpResponseContentType);

View solution in original post

8 REPLIES 8

Omkar Mone
Mega Sage

Hi 

PFB the link where your issue is explained.

 

https://community.servicenow.com/community?id=community_question&sys_id=3451d32ddbdcdbc01dcaf3231f96...

 

Mark Correct if it helps.

Warm Regards,

Omkar Mone

find_real_file.png

www.dxsherpa.com

tried and referred this article, still not working.

Where is your REST message defined ?

Not sure if I understood your question, its under rest messages and in job I am calling it.