Skip to Content
0
Former Member
Dec 17, 2014 at 06:36 AM

OData.request Simple GET, save response into a Variable

298 Views

Hi Guys

This is my problem. I am using a OData.request to get a value by introducing a specific data and I would like to save the response into a variable.

In this example I get the value and I can display it on the console log, but only inside the OData.request... If I run the the console log outside the OData request, the variable is undefined. How do I save the response of a OData Service in a variable.

onEmail: function (evt){

this._onEmail(evt);

},

_onEmail: function (evt){

var oGetInput = this.getView().byId("iInput");

var oGetValue=oGetInput.getValue();

var serviceRoot = "proxy/http/XXXX:8000/sap/opu/odata/sap/XXXX/Search?EMAIL='"+oGetValue+"'";

var headers = { "Content-Type": "application/json", Accept: "application/json" };

var request = {

requestUri: serviceRoot,

method: "GET",

headers: headers,

data: null

};

OData.request(

request,

function (data, response) {

var filtedPeople = data.results;

this.oPARTNER = filtedPeople[0].PARTNER;

console.log("this.oPartner"+this.oPARTNER);

////////////////////////////////////////////////////////////////////////////

// the result of the console log is correct

////////////////////////////////////////////////////////////////////////////////////

},

function (err) {

alert("Fail: " + err.Message);

}

);

console.log("this.oPartner.outside"+this.oPARTNER);

////////////////////////////////////////////////////////////////////////////

// In here the parameter is undefined

////////////////////////////////////////////////////////////////////////////////////

},

Regards

Henry