cancel
Showing results for 
Search instead for 
Did you mean: 

how to schedule an outbound http request in XSJS

Former Member
0 Kudos

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;

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Florian,

Thanks for clarifying again 🙂 The goal here is:

Automatically read a web-service to obtain an exchange rate and store this in HANA.

We currently do not have an SAP ERP installed to read exchange rate tables, so this is why we are looking into a webservice.

Any pointers in how to solve are much appreciated

kind regards, Scott

pfefferf
Active Contributor
0 Kudos

Ok, to store the data you do not need to return the response you received from client.getResponse() via the $.response object, cause you have no client.

The simplest way would be to use the $.hdb db interface to store the data in your target table.

Maybe it is also an option you to use SAP Landscape Transformation to replicate the required tables to your HANA instance. From my point of view this would be the better solution for that scenario compared to the usage of a web service call.

Former Member
0 Kudos

Hi Florian,

The source we are trying to read is only available as a webservice. I am really looking for a way to schedule the call of this webservice and return the data,Writing it back to a HANA is not really our challenge as we did this with a procedure already.

Thanks again,

Scott

pfefferf
Active Contributor
0 Kudos

Then I do not get your situation.

You have created an xsjs script which calls a web service returning some exchange rate information. This script is scheduled via an xsjob. The result is stored in a table.

Why and for what you need the $.response in your script and what you wanna reach in addition to the storage of the data in your db?

Former Member
0 Kudos

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

Answers (1)

Answers (1)

k_gorin
Participant

You should try to run you XSJS app as XS service