Skip to Content
0

OData Service : GET, POST,PUT, DELETE methods not working in Ui5 Application ?

May 08, 2017 at 10:27 AM

136

avatar image

Hi ,

I am using Ui5 application to access OData Service, but

1. I am not able to use CRUD functions, except READ.

2. Using Eclipse to build Application.

3. Odata Service Created in ECC system.

4. CSRF token not received, using FETCH in header(possible root cause of problem).

5. GET,POST,PUT all not working.

6. Only able to fetch data using entity set.

7. Odata service is created for Table, want to read,create,update & delete entries.

8. No error in browser console.

Sharing Code Snippet of Create(save method)

Save: function() {

var oEntry = {};

oEntry.Empid= sap.ui.getCore().byId("Id").getValue();

oEntry.Empname= sap.ui.getCore().byId("Name").getValue();

oEntry.Empadd= sap.ui.getCore().byId("Address").getValue();

oEntry.Empdes= sap.ui.getCore().byId("Role").getValue();

OData.request({ requestUri : "http://xxxx/ZPREKA_ALPHA1_SRV/Employee1Set",

method : "GET",

headers : {

"X­Requested­With" : "XMLHttpRequest",

"Content­Type" : "application/atom+xml",

"DataServiceVersion" : "2.0",

"X­CSRF­Token" : "Fetch" },

user : 'xxx',

password : 'xxxx',

},

function(data, response)

{

try {

var iModel = new sap.ui.model.odata.ODataModel("http://xxx/ZPREKA_ALPHA1_SRV/",true,'xxx','xxx''); iModel.refreshSecurityToken(); ///refresh token

var mydata = iModel.getData();

}

catch(e) {

alert("error");

};

console.log(response);

header_xcsrf_token = response.headers['x-csrf-token'];

var oHeaders = { "x­csrf­token" : header_xcsrf_token, 'Accept' : 'application/json', }; OData.request(

{

requestUri : "http://xxxx/ZPREKA_ALPHA1_SRV/Employee1Set",

method : "POST",

headers : oHeaders,

user : "xxxx",

password : "xxxx",

data:oEntry },

function(data,request)

{

alert("Employee Created Successfully");

location.reload(true);

},

function(err)

{

console.log(err);

alert("Employee Creation Failed");

});

},

function(err)

{

var request = err.request;

var response = err.response;

alert("Error in Get — Request " + request + " Response " + response);

});

},

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers