Skip to Content

Facing issue while calling Function Import of a Service URI

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 );
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    Posted on Dec 28, 2016 at 07:44 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 27, 2016 at 01:01 PM

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

    oModel.callFunction("PersonTaskTimespend", parameters );
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 27, 2016 at 01:27 PM

    are u sure it is syntax error?

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 27, 2016 at 03:48 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 27, 2016 at 04:08 PM

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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 28, 2016 at 02:22 AM

    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.

    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.