Skip to Content
0
Former Member
Mar 26, 2014 at 11:04 AM

Problem submitting batch request for sales order creation

123 Views

Hello experts,

I have created a gateway service, implementing the CREATE_DEEP_ENTITY for order creation. I have tested my service with the Chrome Advanced Rest Client and it works fine with the following XML request:

<?xml version="1.0" encoding="UTF-8"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <atom:content type="application/xml">
  <m:properties>
  <d:OrderId>0</d:OrderId>
  <d:DocumentType>TA</d:DocumentType>
  <d:CustomerId>C6603</d:CustomerId>
  <d:SalesOrg>S010</d:SalesOrg>
  <d:DistChannel>01</d:DistChannel>
  <d:Division>01</d:Division>
  <d:DocumentDate m:null="true" />
  <d:OrderValue m:null="true" />
  <d:Currency m:null="true" />
  </m:properties>
  </atom:content>
  <atom:link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SOItems" type="application/atom+xml;type=feed" title="SALESORDERTSCH.SOHeader_SOItems">
  <m:inline>
  <atom:feed>
  <atom:entry>
  <atom:content type="application/xml">
  <m:properties>
  <d:OrderId>0</d:OrderId>
  <d:Item>000010</d:Item>
  <d:Material>C20013</d:Material>
  <d:Plant m:null="true" />
  <d:Quantity m:Type="Edm.Decimal">100.000</d:Quantity>
  <d:Description m:null="true" />
  <d:UoM m:null="true" />
  <d:Value m:null="true" />
  </m:properties>
  </atom:content>
  </atom:entry>
  <atom:entry>
  <atom:content type="application/xml">
  <m:properties>
  <d:OrderId>0</d:OrderId>
  <d:Item>000020</d:Item>
  <d:Material>C20014</d:Material>
  <d:Plant m:null="true" />
  <d:Quantity m:Type="Edm.Decimal">200.000</d:Quantity>
  <d:Description m:null="true" />
  <d:UoM m:null="true" />
  <d:Value m:null="true" />
  </m:properties>
  </atom:content>
  </atom:entry>
  </atom:feed>
  </m:inline>
  </atom:link>
</atom:entry>

Now that my service is working, I want to be able to call it from a SAP UI5/Javascript application. In order to process multiple items for one order header, I use the OData batch request. Here is my Javascript method that is being processed:

executeOrderCreation : function() {
  // Retrieve model from controller
  var oModel = sap.ui.getCore().getModel();
  oModel.setHeaders(
  { "Access-Control-Allow-Origin" : "*",
  "Content-Type": "application/x-www-form-urlencoded",
  "X-CSRF-Token":"Fetch" }
  );

  // Define data to be created
  var headerData = {
  OrderId : "0",
  DocumentType: "TA",
  CustomerId : "C6603",
  SalesOrg : "S010",
  DistChannel : "01",
  Division : "01",
  DocumentDate : null,
  OrderValue : null,
  Currency : null,
  };

  varItemData1 = {
  OrderId : "0",
  Item : "000010",
  Material : "C20013",
  Plant : null,
  Quantity : "100.000",
  Description :null,
  UoM :null,
  Value :null,
  };

  varItemData2 = {
  OrderId : "0",
  Item : "000020",
  Material : "C20014",
  Plant : null,
  Quantity : "100.000",
  Description :null,
  UoM :null,
  Value :null,
  };

  var batchChanges = [];


  oModel.refreshSecurityToken(function(oData, oResponse){
  alert("Refresh token OK");
  }, function() {
  alert("Refresh token failed");
  }, false);

  oModel.read('/SOHeaders/?$Batch', null, null, false, function(oData, oResponse) {
  // Create batch data
  batchChanges.push(oModel.createBatchOperation("SOHeaders", "POST",headerData ));
  batchChanges.push(oModel.createBatchOperation("SOHeaders", "POST",varItemData1 ));
  batchChanges.push(oModel.createBatchOperation("SOHeaders", "POST",varItemData2 ));
  oModel.addBatchChangeOperations(batchChanges);

  // Submit changes and refresh the model
  oModel.submitBatch(
  function(oData) {
  oModel.refresh();
  },
  function(oError) {
  var error = oError;
  alert("Read failed" + error);
  },
  false);


  }, function() {
  alert("Read failed");
  });
},

The result is when I submit the batch, I have an error saying: The following problem occurred: no handler for data -

Am I doing right in the batchChanges creation ? (Header then items)

Why am I facing this error ?

Any help would be greatly appreciated.

Thanks and regards,

Thibault