on 05-08-2017 11:27 AM
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 : {
"XRequestedWith" : "XMLHttpRequest",
"ContentType" : "application/atom+xml",
"DataServiceVersion" : "2.0",
"XCSRFToken" : "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 = { "xcsrftoken" : 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);
});
},
User | Count |
---|---|
77 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.