cancel
Showing results for 
Search instead for 
Did you mean: 

Facing issue while calling Function Import of a Service URI

Sijin_Chandran
Active Contributor
0 Kudos

Hi All,

I am facing issue while calling a Function Import.

Below is my syntax,

            var serviceUri = "https://******************/sap/opu/odata/SAP/ZTSUPRTSTATC_GW_SRV/";
            var oModel = new sap.ui.model.odata.ODataModel(serviceUri, true, "user", "password");
            sap.ui.getCore().setModel(oModel);
            
            var parameters = { method:"GET", 
                               urlParameters : { LowDate : firstDay,HighDate : lastDay },
                               success:function(oData, oResponse) {                  
                                   console.log(oResponse);
                                   console.log(oData);
                                   var valor = oData.results[0].Name;
                                   alert(valor); //"ok"
                                       }, 
                               error:function(oError){
                                     alert("Data retrieval was not successful!");
                                     } 
                             };

oModel.callFunction("PersonTaskTimespend", parameters );

Accepted Solutions (1)

Accepted Solutions (1)

Sijin_Chandran
Active Contributor
0 Kudos

Hi Everyone,

Very thanks for your time.

The issue was CORS issue and got it rectified by making the following changes to Service URI,

//          var serviceUri = "https://*******.*****.******:####/sap/opu/odata/SAP/ZTSUPRTSTATC_GW_SRV/";
            var serviceUri = "proxy/https/*******.*****.******:####/sap/opu/odata/SAP/ZTSUPRTSTATC_GW_SRV/";

So changing https:// with proxy/https/ made the code work.

I had faced the issue while working using WEB IDE , but there in browser Console it was clearly mentioned that CORS issue has been encountered and I got it rectified by prefixing https://cors-anywhere.herokuapp.com/

but now am using Eclipse and here it was not highlighted in browser Console that the issue was CORS.

Thanks,

Sijin

Answers (5)

Answers (5)

younghwan_kim
Active Participant
0 Kudos

Might work if you change the parameters of your odatamodel.

https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.odata.ODataModel.html#constructor

var oModel =new sap.ui.model.odata.ODataModel(serviceUri, {user:"user", password:"password"});

Also, use odatamodel version 2(sap.ui.model.odata.v2.ODataModel) whenever possible.

junwu
Active Contributor
0 Kudos

deploy to the server where the odata service is to run your app, if not, you have to know how to use proxy.

former_member203031
Contributor
0 Kudos

Hello Sijin,

Please check with the below code :

 oModel.callFunction("/EmployeeSet", "GET", null, null, function (  
          oData, oResponse) {  
             alert("ok");  
          }, function (oError) {  
             alert("err");  
          });  

Kindly let me the if issue still exist.

and if possible paste some screen shot.

Thanks,

Deepak.

junwu
Active Contributor
0 Kudos

are u sure it is syntax error?

Sijin_Chandran
Active Contributor
0 Kudos

If I am removing this code I am getting output.

oModel.callFunction("PersonTaskTimespend", parameters );

And the below is Screenshot of Console.

I want to get response from this Function Import.

Inside onInit only I have added these above mentioned codes.

Thanks,

Sijin

junwu
Active Contributor
0 Kudos

use chrome please

Sijin_Chandran
Active Contributor
0 Kudos

I am facing Syntax error for the below line of code,

oModel.callFunction("PersonTaskTimespend", parameters );