cancel
Showing results for 
Search instead for 
Did you mean: 

Post createBatchOperation SAPUI5

Former Member
0 Kudos

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?

irfan_gokak
Contributor
0 Kudos

Hi,

Which UI5 version you're using?

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member185414
Active Contributor

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.

Former Member
0 Kudos

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

Answers (2)

Answers (2)

former_member484715
Contributor

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

Former Member
0 Kudos

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!

Former Member
0 Kudos

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