Skip to Content
-1

How to make a synchronous request

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 ?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Jan 04, 2019 at 04:08 AM

    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.

    UI5 Odata Promises

    Thanks,

    Vaibhav Maheshwari

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 04, 2019 at 07:31 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 04, 2019 at 08:48 AM

    Nicholas Promises are not supported by IE so I don't know if it's a good use case :D

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.