cancel
Showing results for 
Search instead for 
Did you mean: 

Fiori Elements, SAP Business One Service Layer and "Incomplete batch request body"

nauzet
Explorer
0 Kudos

Hi all,

We are trying Fiori Elements with SAP Business One version for SAP HANA 10.0 (10.00.170) FP 2108.

Using Visual Studio Code and Fiori: "Open application generator", i've created a Fiori Elements app (List Report Object Page).

My goal is to show sales quotation information from Quotations Service Layer endpoint. Everything seems to work fine but when i press "Go" button for fetching the info i receive "Incomplete batch request body":

The problem seems to be related with the endpoint for batches processing.

Inspecting the network browser tab i can see this payload sent to the Service Layer ($batch):

POST http://localhost:8080/b1s/v2/$batch

--batch_id-1635237711263-116
Content-Type:application/http
Content-Transfer-Encoding:binary

GET Quotations?$count=true&$select=CardCode,CardName,DocDate,DocEntry,DocNum,DocTotal&$skip=0&$top=30 HTTP/1.1
Accept:application/json;odata.metadata=minimal;IEEE754Compatible=true
Accept-Language:en-GB
Content-Type:application/json;charset=UTF-8;IEEE754Compatible=true


--batch_id-1635237711263-116--
Group ID: $auto.Workers

Response:

{"error":{"code":"242","message":"Incomplete batch request body."}}

Thank you very much

Kind regards,

Nau

Salim-Satiro
Explorer
0 Kudos

Hi,

Any solution on this ?

Facing the same problem in 2024.

Regards,

Salim

Accepted Solutions (0)

Answers (4)

Answers (4)

andy_bai
Employee
Employee

try add the following entry in the /home/user/projects/app1/webapp/manifest.json

"groupId": "$direct",

"": { "dataSource": "mainService", "preload": true, "settings": { "synchronizationMode": "None", "operationMode": "Server", "autoExpandSelect": true, "groupId": "$direct", "earlyRequests": true } } },
R_Zieschang
Contributor
0 Kudos

Hi,

the reason for this error is, that the Group ID is sent in the batch body request and B1 Service Layer does not like this. If the original body is copied over to postman and the line is removed, SL answers correctly as expected.

I don't know if this is a feature gap within the Service Layer or if it's a bug within SAP UI5 that you can't set how requests are generated.

Initially iirc these Group IDs are meant to be used to separate e.g. long running requests with fast requests. e.g. your application has a header section which shows data from a specific customer (fast) and in your analytic view some data is represented which is gathered by longer running requests.


Nevertheless, you can simply monkey patch your way out of this. The Group ID is initially added here:
sap/ui/model/odata/v4/lib/_Requestor

_Requestor.js

The method in question is sendBatch. So simple monkey patch:

                _Requestor.prototype.sendBatch = function(aRequests, sGroupId) {
                    var oBatchRequest = _Batch.serializeBatchRequest(aRequests,"",
                        this.oModelInterface.isIgnoreETag()
                    );
        
                return this.processOptimisticBatch(aRequests, sGroupId)
                    || this.sendRequest("POST", "$batch" + this.sQueryParams,
                        Object.assign(oBatchRequest.headers, this.mBatchHeaders), oBatchRequest.body
                    ).then(function (oResponse) {
                        if (oResponse.messages !== null) {
                            throw new Error("Unexpected 'sap-messages' response header for batch request");
                        }
                        return _Batch.deserializeBatchResponse(oResponse.contentType, oResponse.body);
                    });
                }

Because the deserializeBatchResponse Method expects the Group ID info also in the response, we need to monkey patch this also (because the deserialisation is not context based but rather depends on the amount of lines which is a bit weird imho). Because of that the JSON string which will be deserialized is missing a closing '}'.

const originalDeserializeBatchResponse = _Batch.deserializeBatchResponse;
                _Batch.deserializeBatchResponse = function(contentType, body) {
                    let originalReturn = originalDeserializeBatchResponse.apply(this, [contentType, body]);
                    originalReturn.forEach(element => {
                        element.responseText = element.responseText + '}';
                    });
                    return originalReturn;
                }

With these small adaptions it is possible to retrieve data from the SL.

Please be aware, that monkey patching can be considered "dirty", so it would be better to either open a ticket to the b1 team to clearify or to open a ticket to the sapui5 team and discuss the batch behavior with b1 sl as odata service.

HTH
Robert

MatLakaemper
Participant
0 Kudos

Hi,

i am Working with SBO10 FP 2208

Project with VisualStudio Code,
i am running still in the same error. "groupId":"direct" doesn´t help

any suggestions?

kind Regards,
Matthias Lakaemper

--------------------------------------
HTTP request was not processed because $batch failed

Incomplete batch request body.

snippet from manifest.json"models": { "i18n": { "type": "sap.ui.model.resource.ResourceModel", "settings": { "bundleName": "unimat.servicecall6.i18n.i18n" } }, "": { "dataSource": "mainService", "preload": true, "settings": { "synchronizationMode": "None", "operationMode": "Server", "autoExpandSelect": true, "groupId": "$direct", "earlyRequests": true } }, "@i18n": { "type": "sap.ui.model.resource.ResourceModel", "uri": "i18n/i18n.properties" } },
DavidAndrusko
Advisor
Advisor
0 Kudos

Hi Nau,

You may find the following blog post useful with some useful code samples on GitHub also for Service Layer.

SAP Business One on HANA Development E-learning is Live! Now also on Youtube.

Kind regards,

David Andrusko