Skip to Content
0

Post createBatchOperation SAPUI5

Dec 15, 2017 at 07:51 PM

106

avatar image

Hey Everyone,

I am trying to get my POST call working using Batch but I am getting an error about my payload. I am new to SAPUI5 and am looking for guidance.

I am getting this error when I make the call from the UI

error.jpg

When I execute the call I am trying to replicate in SAP Gateway Client it looks as so and it works.

--batch
Content-Type: multipart/mixed; boundary=changeset

--changeset
Content-Type: application/http
Content-Transfer-Encoding: binary

POST SRMShoppingCartItemCollection(NUMBER_INT='0000000001',OBJECT_ID='1004266',DOC_MODE='EDIT',WIID='000000000000')/ItemAccountAssignmentNavigation HTTP/1.1

Content-Type: application/atom+xml
Accept: application/atomsvc+xml;q=0.8, application/json;odata=fullmetadata;q=0.7, application/json;q=0.5, */*;q=0.1
DataServiceVersion: 1.0
MaxDataServiceVersion: 3.0
Content-Length: 372

<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:NUMBER_INT>0000000001</d:NUMBER_INT><d:OBJECT_ID>1004266</d:OBJECT_ID></m:properties></a:content></a:entry>
--changeset--
--batch--


However, When I try to submit through my custom exit in BATCH I am unsure how I am to submit the BODY of the payload?


var sServiceUrlBatch = "/sap/opu/odata/srmnxp/SRMSHOPPING_CART/";
//var metadata = Appcc.getMetadata("accAssignment");
var view = controller.getView();
var assetList = [];
var that = view.getController();
var batchModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/srmnxp/SRMSHOPPING_CART/", true);
var batchChanges = [];
var json2 = {
              number_int  : "0000000001",
              object_id   : 1004277,            
            }
for ( var k = 0; k < 2; k++ ) {
  batchChanges.push(batchModel.createBatchOperation("SRMShoppingCartItemCollection(NUMBER_INT='0000000001',OBJECT_ID='1004277',DOC_MODE='EDIT',WIID='000000000000')/ItemAccountAssignmentNavigation", "POST", json2) );
}
batchModel.addBatchChangeOperations(batchChanges);
batchModel.submitBatch();
batchModel.refresh();

How can I put my JSON2 variable in the correct format that the gateway call is looking for?

error.jpg (258.8 kB)
10 |10000 characters needed characters left characters exceeded

Hi,

Which UI5 version you're using?

0

the version installed is 1.24.2 and we won't be upgrading until next year.

0
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Ankit Maskara
Dec 19, 2017 at 06:00 PM
1

error for XML stream parsing is a generic error which occurs when the data type and field values in payload are incongruent. In your case I see at one place OBJECT_ID is in quotes while at another it's not? Also such error can occur if the name of property is different in actual payload and metadata.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Ankit,

Thanks for your answer. I had Object_ID not in quotes as it did not have quotes when I tested in SAP Gateway client.

However, adding them made it work! :-)

Here is the updated solution that works.

var sServiceUrlBatch = "/sap/opu/odata/srmnxp/SRMSHOPPING_CART/";
var view = controller.getView();
var assetList = [];
var that = view.getController();
var batchModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/srmnxp/SRMSHOPPING_CART/", true);
var batchChanges = [];
var json2 = {
              NUMBER_INT  : "0000000001",
              OBJECT_ID   : "1004277",
              DOC_MODE    : "EDIT",
              WIID        : "000000000000",
            }
for ( var k = 0; k < 2; k++ ) {
  batchChanges.push(batchModel.createBatchOperation("SRMShoppingCartItemCollection(NUMBER_INT='0000000001',OBJECT_ID='1004277',DOC_MODE='EDIT',WIID='000000000000')/ItemAccountAssignmentNavigation", "POST", json2) );
}

batchModel.addBatchChangeOperations(batchChanges);
batchModel.submitBatch();
batchModel.refresh();

0
Arjun Biswas Dec 16, 2017 at 04:10 AM
1

Hi Keith Warnock,

As per my understanding, you are committing some mistake in your HTTP Request, as even a extra space can cause errors.

Regards,

Arjun Biswas

Show 1 Share
10 |10000 characters needed characters left characters exceeded

is there any tool I can use to see where the error might be?

As stated, it works through SAP Gateway Client, however, in my SAPUI5 I get an error.

Thanks!

0
Keith Warnock Dec 15, 2017 at 08:24 PM
0

On the gateway side, I see the following request data payload, the error on gateway is "Error while parsing an XML stream"


error3.jpg (331.8 kB)
Share
10 |10000 characters needed characters left characters exceeded