on 06-22-2015 1:46 PM
Hi All,
I need to insert the data in Database through OData model.Can you please help me?
Below is my code:
submitLineItem : function() {
var grdata = new Object();
OData
.request(
{
requestUri : "http://host:8000/sap/opu/odata/sap/ZMM_GR_APP_SRV_01/PO_ItemSet(Ebeln=%273005000274%27)/PO_ItemSet",
method : "GET",
headers : {
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" : "application/atom+xml",
"DataServiceVersion" : "2.0",
"X-CSRF-Token" : "Fetch"
}
},
function(data, response) {
header_xcsrf_token = response.headers['x-csrf-token'];
console.log(data.results);
grdata.material = data.results.Matnr;
grdata.plant = data.results.Werks;
grdata.stgeloc = data.results.Lgort;
grdata.vendor = data.results.Emlif;
grdata.ponumber = data.results.Ebeln;
grdata.poItem = data.results.Ebelp;
console.log(header_xcsrf_token);
OData
.request(
{
requestUri : "http://host:8000/sap/opu/odata/sap/ZMM_GR_APP_SRV_01/GRSet",
method : "POST",
headers : {
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" : "application/atom+xml",
"DataServiceVersion" : "2.0",
"Accept" : "application/atom+xml,application/atomsvc+xml,application/xml",
"X-CSRF-Token" : header_xcsrf_token
},
data : {
GmCode : '01',
Id : 00001,
Number : 222,
PstngDate : '1434634546',
DocDate : '1147046400000',
RefDocNo : '0001',
Material : grdata.material,//getting from response
Plant : grdata.plant,//getting from response
StgeLoc : LineUpdatedData.storageLoc,//getting from response
MoveType : '101',
Vendor : grdata.vendor,//getting from response
EntryQnt : LineUpdatedData.quantity,//getting from response
EntryUom : 001,
PoNumber : grdata.ponumber,//getting from response
PoItem : grdata.poItem,//getting from response
MvtInd : 'x'
}
},
function(data,
response) {
alert("success");
cosole
.log(data);
cosole
.log(response);
},
function(err) {
console
.log(err);
alert(err);
});
}, function(err) {
var request = err.request; // the
// request
// that
// was
// sent.
var response = err.response; // the
// response
// that
// was
// received.
alert("Error in Get -- Request "
+ request + " Response "
+ response);
});
},
When I am using above code, I am getting Bad request error
Please resolve this error.
Thanks in advance.
Check for the error you got while running this transaction.
/IWFND/error_log in SAP system.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
your code is fine. what is the issue?
why you are hard coded to post? and what about grdata?
400 bad request -
1. filed to sent some required data to back end.
2. date is not sending proper manner.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.