Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to post data to oData in sapui5(Insert)?

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.

Former Member
Not what you were looking for? View more on this topic or Ask a question