on 09-04-2014 8:17 AM
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
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
Hello Sarosh,
Since u say u are able to POST the data with the payload shared by u via REST Client, then some thing is to be addressed in UI Code level.
I think u need to ask UI Code in to get appropriate answer.
Please cross check the format of payload u generate in the UI Code Level at the run-time.
Regards,
Ashwin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sarosh,
Are you able to post the sales order items. We are also facing the same issue. If it is solved, can you post the code here.
Thanks in advance.
SK
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
CustomerName and BusinessPartnerID in requestORderHeader and ProductID and ProductName in
itemData.push({QuantityUnit:'EA', Tax:'73.53', ProductName:'SAROSH2 ID 0700000049', Quantity:'3.0', ProductID:'HT-8822', DeliveryDate:'\/Date(1384992000000)\/'});
are the foreign keys so they should exist in their respective table,this was the mistake I was doing.so just make sure the input value you provide are valid.Hope this helps
Hi Sarosh,
Can you post your complete code for posting header and Item data. BTW below is the my item data I am trying to post.
itemdata =
{
Material: material_1,
Plant: plant,
MoveStloc : to,
EntryQnt: quantity_1,
StgeLoc: from,
}
var batchChanges = [];
batchChanges.push(this.oModel.createBatchOperation(entityset,"POST", itemdata));
Thanks in advance.
SK
Are u giving the valid data in these variables (the thing I stated earlier )?
Create: function(oEvent) {
var view = this.getView();
var myInteger = (/^-?\d*(\.\d+)?$/);
if( !view.byId("Tax").getValue().match(myInteger) )
{
alert("Tax Should be a number");
return;
}
var serviceUrl = "proxy1/gateway/odata/sap/ZCD204_EPM_DEMO_SRV;v=1";
var createsrv= "proxy1/gateway/odata/sap/ZCD204_EPM_DEMO_SRV;v=1/SalesOrders";
var requestORderHeader = {};
requestORderHeader.Tax=view.byId("hTax").getValue();
requestORderHeader.Currency=view.byId("hCurrency").getValue();
requestORderHeader.CustomerName=view.byId("hCustomerName").getValue();
requestORderHeader.Note=view.byId("hNote").getValue();
requestORderHeader.BusinessPartnerID=view.byId("hBusinessPartnerID").getInfo();
requestORderHeader.SalesOrderItems=window.itemDataArr;
// alert(window.JSON.stringify(requestORderHeader));
OData.request
({
requestUri: createsrv,
method: "GET",
headers:
{ "X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"Access-Control-Allow-Origin" : "*",
"X-CSRF-Token":"Fetch" }
},
function (data, response)
{
var token = response.headers['X-CSRF-Token'];
alert(token);
OData.request
({
requestUri:createsrv,
method: "POST",
headers: {
"Content-Type": "application/atom+xml",
"Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
"X-CSRF-Token": token },
data: requestORderHeader
},
function (data, response)
{
document.location.reload(true);
$("<div>Returned data " + window.JSON.stringify(data) + "</div>").appendTo($("#MessageDiv"));
},
function (err) {
}
);
},
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
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.