on 2019 Jan 04 1:58 AM
Hi i did a request bus others request i want to receive in order like
main request > if it's ok i made other request > if the previous request was success i made a last request
i was reading and odata v2 is deprecated, with odata v4 could i do this ? or is there any way to make a function with as many requestas i need and send them all and just when all this request are ok keep executing the rest of my code ?
Hello. You can do this with a promise. I would suggest not to make a synchronous call. It may lock the app until the call is done.
Promise:
getSomething:function(){
//"sap/ui/model/odata/v2/ODataModel"
var oModel = new ODataModel(params);
var urlParameters = {} //If you need some params
return new Promise(function (resolve, reject) {
oModel.read(sPath, {
urlParameters: urlParameters,
success: function (data) {
resolve(data);
},
error: function (err) {
reject(err);
}
});
}
}
Call it and wait for the response
this.getSomething().then(function(result){
//Things are ok and do something with the data
console.log(result);
}).catch(function(err){
//something went wrong. the reject in the promise has runn.
console.log(err)
});
This is the easiest way of doing this. If you want some better code, you can also write return result; and add another then(). That is where it will runn.
To make it run in IE add the bluebird lib
http://bluebirdjs.com/docs/getting-started.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@naotoxxx
Sounds like alot of intervals and checking if a object has data. Sounds hard.
https://www.w3schools.com/jsref/met_win_setinterval.asp
personally i dont see why you would not use a promise. http://bluebirdjs.com/docs/why-bluebird.html makes promise runn on Netscape 7......
Hi Naoto,
Not sure where you read, odata v2 is not deprecated as of now.
However odata v4 is the latest version available.
You can use promise to chain your requests and execute your code if all are successful.
Thanks,
Vaibhav Maheshwari
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nicholas Promises are not supported by IE so I don't know if it's a good use case 😄
Anyway, I need to adivce you: never ever do synchronous requests. They are a really bad habit and there's not a good side about it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
maheshkumar.palavalli ericci Just wanted to say that UI5 comes with a Promise polyfill: https://github.com/SAP/openui5/blob/fdc3334431fbfe1776e884826299f8103499ef9b/src/sap.ui.core/src/sap...
While it's true that IE doesn't support Promises natively, all Promise based APIs in UI5 still work on any platforms thanks to the polyfill.
Boghyon Hoffmann, Super!! Thant's why i never got any errors when i used promises also.
> Which other ES6 features are added with polyfill?
Since 1.64, quite a lot 🙂 See the commit https://github.com/SAP/openui5/commit/49528d10ffd8f146146675035f611feb43d26621
Complete list of supported APIs from the original lib: https://github.com/paulmillr/es6-shim
User | Count |
---|---|
69 | |
11 | |
10 | |
10 | |
9 | |
9 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.