cancel
Showing results for 
Search instead for 
Did you mean: 

Syncoronous Call for Sap Odata V2 Model

zayidu
Participant
0 Kudos

Hello Experts,

I want to know how can I execute Odata.READ calls synchronously. Below is my code: I tried async: false as we do in Odata V1 model, but it didn't work.

Is there any other way other than using event handlers attachRequestSent() and attachRequestCompleted() to achieve synchronous execution in Odata Calls. Your quick response is much appreciated!

this.oModel.read('/ZST_REPORT(1)', { 
                    // async: false,
                    success: function(oData, oResponse) {
                        that.FLAG_SET_LOB = oData.ID;

                    },
                    error: function(request, error) {
                        sap.m.MessageToast.show("Server Error in LOB Data: Please Contact Technical Team, if problem persists.");
                    }
                });


Thanks,

Zayid

boghyon
Product and Topic Expert
Product and Topic Expert
0 Kudos

Please do not send any requests synchronously! The whole web platform including UI5 is trying hard to finally move away from sync XHR because it freezes the UI-thread (main-thread) of the browser during the round trips.

Please enhance the question with more information explaining what exactly you're trying to achieve. Maybe we can find a better solution than relying on sync XHRs.

Accepted Solutions (0)

Answers (1)

Answers (1)

prashil
Advisor
Advisor
0 Kudos

Hi Zayid,

After reading the documentation, I don't think there is any parameter as async to make the request synchronous. Read call in V2 is always and default asynchronous.

The other question regarding the event, there are requestSent, requestFailed and requestCompleted and in case of batch, batchRequestSent, batchRequestCompleted and batchRequestFailed can be attached to the model directly.

In case, if you still like to make the sync call, use $.ajax. In this case, you have to handle creating the request url and so on.

Thanks

Prashil