cancel
Showing results for 
Search instead for 
Did you mean: 

How to do create operation in Json model?

former_member184238
Participant
0 Kudos

Hi,

I have done sample application which is having create operation using oData model by following the below link.

http://scn.sap.com/community/developer-center/front-end/blog/2012/06/06/sample-ume-application-using...

It's working fine and I can create the records in back end.

Now I am doing same application for mobile using JSON Model .In that application when I am sending request to the back end in the same way I am getting the below error message.

CX_SXML_PARSE_ERROR/001560AA0E081DEB8CA398CC1690D406Error while parsing an XML stream206B32E3A013F1A29B1D20CF30C48576

when I observe the xml data in  Request Payload for both desktop and mobile applications, they are in different format.

Please suggest me , If any one knows to send the data to the back end with CSRF token in JSON model not in oData model

Thanks&Regards

Sridevi.G

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

can you post your the payload you are trying to post?

Regards

Stefan

former_member184238
Participant
0 Kudos

Hi,

I used the below code when I am using Odata model in my application.

OData.request({

requestUri : "http://xxxx:8000/sap/opu/odata/EAE/SERVICE_ENTRYSHEET_SRV/PurchaseOrderItems(PoDocnum='"+ PoDocnum+ "',PoItem='"+ PoItem+ "')?$expand=ServiceSet",

method : "GET",

headers : {

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

"Content-Type" : "application/atom+xml ",

"DataServiceVersion" : "2.0",

"X-CSRF-Token" : "Fetch"

}

},

function(data, response) {

console.log(response);

var header_xcsrf_token = response.headers['x-csrf-token'];

   OData.request({

     requestUri : "http://192.168.1.25:8000/sap/opu/odata/EAE/SERVICE_ENTRYSHEET_SRV/PurchaseOrderItems",

     method : "POST",

     headers : {

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

         "Content-Type" : "application/atom+xml;type=entry",

         "DataServiceVersion" : "2.0",

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

         "x-csrf-token" : header_xcsrf_token

            },

         data : totaldata

    },

  function(data,response) {

         sap.ui.commons.MessageBox.alert("successfully Created");

        $("<div>Returned data "+ window.JSON.stringify(data)+ "</div>").appendTo($("#MessageDiv"));

  },

function(err) {

    alert('error ');

    console.log(err);

    var result = $(errormsg).find("message").text().split(".")[0];

   });

}, function(err) {

var request = err.request;

var response = err.response;

});

It's working fine in browser and I can create records in back end.

For my mobile application I am using JSON model.But to create record I used the same code. Then I am getting the following error message.

CX_SXML_PARSE_ERROR/001560AA0E081DEB8CA398CC1690D406Error while parsing an XML stream206B32E3A013F1A29B1D20CF30C48576

The following is XML which is generated dynamically when I am sending post request.

XML Generated in Odata model.

   

<entry xmlns="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"><author><name/></author><title/><content type="application/xml"><m:properties><d:AccAssignCat/><d:CompanyCode>1000</d:CompanyCode><d:CompanyName>IDES AG</d:CompanyName><d:Currency>EUR</d:Currency><d:DeliveryStatus/><d:Material/><d:Measurement>C62</d:Measurement><d:NetPrice>100.00</d:NetPrice><d:Packno>0100005643</d:Packno><d:PoDocnum>4500017608</d:PoDocnum><d:PoItem>00010</d:PoItem><d:PriceDate>2013-09-26T00:00:00</d:PriceDate><d:Quantity>1.000</d:Quantity></m:properties></content><link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ServiceSet" href="" type="application/atom+xml;type=feed"><m:inline><feed><entry><author><name/></author><title/><content type="application/xml"><m:properties><d:PoDocnum>4500017608</d:PoDocnum><d:PoItem>00010</d:PoItem><d:Updateitem>X</d:Updateitem><d:Extrow>0000000010</d:Extrow><d:Introw>0000000000</d:Introw><d:ShortText>Test 1</d:ShortText><d:TotalQuantity>10.000</d:TotalQuantity><d:Quantity>2.000</d:Quantity><d:ActQuantity>1</d:ActQuantity><d:UnitMeasurement>EA</d:UnitMeasurement><d:GrossPrice>10.00</d:GrossPrice><d:Currency>EUR</d:Currency><d:Packno>0100005644</d:Packno></m:properties></content></entry></feed></m:inline></link></entry>

XML Generated in JSON model.


<a:entry xmlns:a="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"><a:author><a:name/></a:author><a:content type="application/xml"><m:properties><d:AccAssignCat m:type="Edm.String"/><d:CompanyCode m:type="Edm.String">1000</d:CompanyCode><d:CompanyName m:type="Edm.String">IDES AG</d:CompanyName><d:Currency m:type="Edm.String">EUR</d:Currency><d:DeliveryStatus m:type="Edm.String"/><d:Material m:type="Edm.String"/><d:Measurement m:type="Edm.String">C62</d:Measurement><d:NetPrice m:type="Edm.String">100.00</d:NetPrice><d:Packno m:type="Edm.String">0100005643</d:Packno><d:PoDocnum m:type="Edm.String">4500017608</d:PoDocnum><d:PoItem m:type="Edm.String">00010</d:PoItem><d:PriceDate m:type="Edm.String">2013-09-26T00:00:00</d:PriceDate><d:Quantity m:type="Edm.String">1.000</d:Quantity></m:properties></a:content><a:link href="" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ServiceSet" type="application/atom+xml;type=feed"><m:inline><a:feed><a:entry><a:author><a:name/></a:author><a:content type="application/xml"><m:properties><d:ActQuantity m:type="Edm.String">1</d:ActQuantity><d:CostCenter m:type="Edm.String"/><d:Currency m:type="Edm.String">EUR</d:Currency><d:Extgroup m:type="Edm.String"/><d:Extrow m:type="Edm.String">0000000010</d:Extrow><d:GrossPrice m:type="Edm.String">10.00</d:GrossPrice><d:Introw m:type="Edm.String">0000000000</d:Introw><d:Packno m:type="Edm.String">0100005644</d:Packno><d:PersNumber m:type="Edm.String"/><d:PoDocnum m:type="Edm.String">4500017608</d:PoDocnum><d:PoItem m:type="Edm.String">00010</d:PoItem><d:Quantity m:type="Edm.String">2.000</d:Quantity><d:Serviceno m:type="Edm.String"/><d:ShortText m:type="Edm.String">Test 1</d:ShortText><d:SubPackno m:type="Edm.String">0000000000</d:SubPackno><d:TotalQuantity m:type="Edm.String">10.000</d:TotalQuantity><d:UnitMeasurement m:type="Edm.String">EA</d:UnitMeasurement><d:Updateitem m:type="Edm.String">x</d:Updateitem></m:properties></a:content></a:entry></a:feed></m:inline></a:link></a:entry>

In this XML it automatically appends that datatype to the value.

I don't know another approach to send CSRF token dynamically in JSON model.

Please help me to solve that issue.

Thanks&Regards

Sridevi.G

Former Member
0 Kudos

Hi,

I have not experienced problems with the CSRF token.

But maybe these threads can help you:

http://scn.sap.com/thread/3185017

http://scn.sap.com/thread/3386003

Regards

Stefan