cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5: How to make an asynchronous OData .create() request?

Former Member
0 Kudos

Hi,

In my sapui5 app, I have an animation made by progress indicator which is running while waiting for the response of an OData model .create() service. However, the animation stops after the request is sent.

Does anyone know how to make an async .create() OData request?

Thanks a lot!

My code look like this:

oODModel = new sap.ui.model.odata.ODataModel(myUrl);

oEntry = myNewDataEntry;

myAnimationIndicator.start();    //animation starts to run

var onSuccess = function(){myAnimationIndicator.stop();};

var onError = function(){myAnimationIndicator.stop();};

oODModel.create('myDataSet',oEntry, null, onSuccess, onError);

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi ,

Please pass true in the call creat(sPath, oData, oContext?, fnSuccess?, fnError?, true) to make async request.

Thanks,

Arun

Former Member
0 Kudos

Hey,

You can give it a try with the below snippet which is working fine for me.

var onSuccess = function(){myAnimationIndicator.stop();};

var onError = function(){myAnimationIndicator.stop();};


var reqHeaders = {

                    context: this,// mention the context you want

                    success: onSuccess, // success call back method

                    error: onError, // error call back method

                    async: true // flage for async true

                };

// show the loader here

myAnimationIndicator.start();

oODModel = new sap.ui.model.odata.ODataModel(myUrl);

oEntry = myNewDataEntry;

oODModel.create('myDataSet',oEntry, reqHeaders );

Former Member
0 Kudos

Hi, I would like to ask a question about your solution.

What is context: this for? I am not very sure what the context is for and what object this is supposed to be.

vince_tebano
Explorer
0 Kudos

According to the SAPUI5 documentation:

Was not released until Version 1.20

former_member182372
Active Contributor
0 Kudos

try to place odatamodel.create in

window.setTimeout(function() { <HERE> }, 100);

Former Member
0 Kudos

Hi there,

This issue still not solved. Anyone has ideas? Override create method or?

Thanks.

Dong

Former Member
0 Kudos

Why not update your UI5 version ?

Former Member
0 Kudos

Hi Sakthivel,

Could you kindly povide the link to the sapui5 version you mentioned? I cannot find 1.19.1, and your old link does not work either. The official one is 1.18 only?

Thanks a lot.

Dong

Former Member
0 Kudos

Hi Dong,

y do u need 1.19?

1.18 supports that feature, as you can see here: SAPUI5 SDK - Demo Kit

And download is available here: OpenUI5 - Download

Greets,

ben

Former Member
0 Kudos

Hi,

Now I have updated sapui5 to 1.18.10, but the progressindicator animation is still not running while waiting for the resp, though I set async for .create() req. Has anyone tried similar thing before?

The animation is started by calling a function, say, startIndicator(), which actually running in an infinite loop showing the moving progress bar. I wonder teh problem is due to the way how to start the indicator while sending the req.

Thanks.

Dong

Former Member
0 Kudos

Hi Dong,

I'm not sure if the parameter is for asynchronous request for the "real data", since it's called "bLoadMetadataAsync". I guess it's only for the metedata document to be loaded asynchrone - but maybe somebody else can say more.

Greets,

ben

Former Member
0 Kudos

Hi Ben,

Thanks for the tip. I will dig into it and hopefully someone else would come up with some ideas.

Br,


Dong

Former Member
0 Kudos

Hi,


try


oODModel.create('myDataSet',oEntry, null, onSuccess, onError,true); //true sets asyn


The last paramter is a boolean, which decides to be async or sync.


Regards

Sakthivel

Former Member
0 Kudos

Hi Sakthivel,

Thanks for the quick reply. But I looked the API:

    creat(sPath, oData, oContext?, fnSuccess?, fnError?)

    Trigger a POST request to the odata service that was specified in the model constructor.

which does not seem to have a flag bAsync param. Anyway, I will have a quick try.

Br,

Dong

Former Member
0 Kudos

Hi Dong,

I'm referring to the UI5 1.19.1 Version. Here's the API

http://veui5infra.dhcp.wdf.sap.corp:8080/demokit/#docs/api/symbols/sap.ui.model.odata.ODataModel.htm...

Regards

Sakthivel

Former Member
0 Kudos

Hi Sakthivel,

I am using SAPUI5 1.14.6, no wonder why the API is different. Thanks very much for the info.

By the way, can you paste the API lines of .creat() method? I cannot open the site now. Just want to see the details of the method.

Br,

Dong

P.S:

@SAP: I sincerely hope the latest changes of API can be reflected on the official website which we developers use serioesly. Thanks very much in advance!