Skip to Content
avatar image
Former Member

how to schedule an outbound http request in XSJS

Hi all,

We have some code to do an outbound http call and write te response to a table when we call it manually this works fine. However when I try to automate this in via an xsjob, I keep getting the message: $.response is undefined.

Any help would be greatly appreciated.

Kind regards,

Scott Wery

--partial code below

var destination_package= "remiqz.ETL";
var destination_name= "Exchange_Rate";
function run(){
try {
//Coding for exchange rates import
var dest= $.net.http.readDestination(destination_package, destination_name);
var client= new $.net.http.Client();
var req= new $.web.WebRequest($.net.http.GET, "?base=EUR&symbols=USD,GBP");
client.request(req, dest);
var response = client.getResponse();

$.response.contentType= "application/json";
$.response.setBody(response.body.asString());
$.response.status= $.net.http.OK;

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Mar 29, 2017 at 04:44 AM

    Objects like $.response or $.request are not available in background processing. They are only available in case you call the xsjs script via a client (like a browser).

    The question is what you wanna really reach. I don't think, that you wanna set the response for a specific client call in background processing.

    Regards,
    Florian

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Florian,
      indeed removing $.response fixed it.
      Initially we tried this but encountered an error, which led to us trying to try to work with the response.
      Thanks again for you help,

      Scott

  • Mar 29, 2017 at 08:09 AM

    You should try to run you XSJS app as XS service

    Add comment
    10|10000 characters needed characters exceeded