Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

Deep Insert SalesOrder SAPUI5 Odatamodel

$
0
0

Hi all I am performing deep insert operations on sap gateway demo services https://sapes1.sapdevcenter.com/sap/opu/odata/sap/ZCD204_EPM_DEMO_SRV/SalesOrders


I have successfully done that using XML via advanced rest client using payload

 

<?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:SalesOrderID></d:SalesOrderID>

<d:Tax>0.00</d:Tax>

<d:Currency>EUR</d:Currency>   

<d:CustomerName>SAROSH</d:CustomerName>

<d:BusinessPartnerID>0100000079</d:BusinessPartnerID>

</m:properties>

   </atom:content>

<atom:link

rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SalesOrderItems"

type="application/atom+xml;type=feed" >

<m:inline>

<atom:feed>

<atom:entry>

<atom:content type="application/xml">

<m:properties>

<d:QuantityUnit>EA</d:QuantityUnit>

<d:Tax>87.4</d:Tax>

<d:ProductName>EPM DG: SO ID 0500000097 Item 0000000010</d:ProductName>

<d:ProductID>HT-1030</d:ProductID>

<d:Quantity>2.0</d:Quantity>

<d:DeliveryDate>2014-08-14T02:00:00.000</d:DeliveryDate>

</m:properties>

</atom:content>

</atom:entry>

</atom:feed>

</m:inline>

</atom:link>

</atom:entry>
but I cant create it in SAPUI5 I am currently following this tutorial

Create a sales order using the deep insert create request with ODataModel


following is my code

 

var serviceUrl = "http://192.168.1.12:8080/gateway/odata/sap/ZCD204_EPM_DEMO_SRV;v=1"; 

  var createsrv= "http://192.168.1.12:8080/gateway/odata/sap/ZCD204_EPM_DEMO_SRV;v=1/SalesOrders";

  var oDialog = sap.ui.getCore().getElementById("Dialog2");

  var oModel = new sap.ui.model.odata.ODataModel(serviceUrl);

 

  var itemData = [];

   itemData.push({QuantityUnit:'EA', Tax:'73.53', ProductName:'SAROSH2 ID 0700000049', Quantity:'3.0', ProductID:'HT-8822', DeliveryDate:'\/Date(1384992000000)\/'});

  ////I have also used this format DeliveryDate:'2014-08-14T02:00:00.000'

  var requestORderHeader = {}; 

  requestORderHeader.SalesOrderID='';

  requestORderHeader.Tax='0.00';

  requestORderHeader.Currency='INR';

  requestORderHeader.CustomerName='TECUM';

  requestORderHeader.BusinessPartnerID='0100000005';

  requestORderHeader.SalesOrderItems=itemData;

  OData.request

  ({ 

  requestUri:      createsrv, 

  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'];

  alert(header_xcsrf_token);

 

 

  oModel.setHeaders( 

  { 

  "X-Requested-With": "XMLHttpRequest",                         

   "Content-Type": "application/json", 

   "DataServiceVersion": "2.0",   

   "Accept": "application/atom+xml,application/atomsvc+xml,application/xml,application/json",  

   "X-CSRF-Token":header_xcsrf_token }  

  );   

  }, 

  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);

  }

  );

  oModel.create('/SalesOrders',  

  requestORderHeader,  

  null,  

  function(oData, oResponse) {  

  alert ('Order creation succeed !'); 

  }, 

  function(err) {  

  alert(window.JSON.stringify(err.response));

  alert('Call service creation failed');  

  } 

  ); 

  oDialog.close();

// }}));

  },

 

If i dont insert the salesOrder items then the record is created elsewise no,
Is it something to do with format?
Is deliverydate formate is correct ?
How to insert salesOrderItems along with salesOrders?

 


Any help would be highly appreciated

Best Regards
Sarosh Bilal


Viewing all articles
Browse latest Browse all 2823

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>