cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAPUI5 callFunction not executed

jakob_steen-petersen
Contributor
4,311

Hi

I have an oData model with an Import Function to check an order. I use this code to call it:

        var oModel = this.getView().getModel();
        oModel.callFunction("/CheckOrder", { "Aufnr" : Order },        
        function(oData, response) { return response;  }, 
                  
        function(oError){} );   

But the function os not called? When i check trace i don´t se any calls - not even erronous calls?

What is wrong?

View Entire Topic
maheshpalavalli
Active Contributor

Check this documentation here :

https://ui5.sap.com/#/api/sap.ui.model.odata.v2.ODataModel%23methods/callFunction

you can pass parameters like mentioned in the api documentation.

oModel.callFunction("/CheckOrder", {
            method: "GET",
            urlParameters: { "Aufnr" : Order },
            success: function(oData, response) {
                
            }.bind(this), // callback function for success
            error: function(oError) {
                
            }.bind(this)
        });   

Thanks,
Mahesh

maheshpalavalli
Active Contributor
0 Likes

you can see in the documentation, they have mParameters, it is an object type, so we are passing that as an object to call function, I am rewriting it as below for better understanding.

var mParameters = {
            method: "GET",
            urlParameters: { "Aufnr" : Order },
            success: function(oData, response) {
                
            }.bind(this), // callback function for success
            error: function(oError) {
                
            }.bind(this)
        };
oModel.callFunction("/CheckOrder", mParameters);   
jakob_steen-petersen
Contributor
0 Likes

Arh - now i understand. Thank you it worked.

The only thing i now need to figure out is this: seems like the call is done Async - i need it synchron in order to stop further processing if the response contains a particular value?!

maheshpalavalli
Active Contributor
0 Likes

jakob.steen-petersen it will be asynchronous, so you have to write code inside success, or wrap your logic inside a function and call it inside the success handler, it's same like your odata read call, whhhiiich I answered in ur previous question.

https://answers.sap.com/questions/13182744/sapui5-odata-read.html?childToView=13183691#comment-13183...

jakob_steen-petersen
Contributor
0 Likes

Actually i did write code inside success... For now just a simple Message:

        var oModel = this.getView().getModel();
	        
        oModel.callFunction("/CheckOrder", {
            method: "GET",
            urlParameters: { "Aufnr" : Order },
            success: function(oData, response) {
                
                MessageBox.error(response);   
                
            }.bind(this), // callback function for success
            error: function(oError) {
                
            }.bind(this)

And i get the message - but it is still issued after further processing of code (i have checked by debugging)

maheshpalavalli
Active Contributor
jakob.steen-petersen , yes it will go immediately as by default the requests that u do with ui5 odata model is asynchronous, so u should not write any code after the callFunction. Once the request is successful (reaches backend and comes back) then the success handler is called. So You should write all the code inside the success handler or simple put that code u want to call after the call fucntion in a separate function method and call it inside the success handler.