0
votes

I am developing a SAPUI5 application that uses the SAP OData service CRM_OPPORTUNITY.

In my program I am trying to do the following request to the OData service

getMax: function(oEvent) {      
    var oModel = this.getOpportunityODataService();
    var maxHitData;

    oModel
        .read(
            "RetrieveMaxHit",
            null,
            null,
            false,
            function(oData, resp) {
                maxHitData = {
                    RetrieveMaxHit: resp.data.results[0]
                };

            });
   return maxHitData;
},

getOpportunityODataService : function(){        
    var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/CRM_OPPORTUNITY/");
    oModel.forceNoCache(true);      
    return oModel;
},

The response to this request does not contain any response Data. resp.data is undefined.

If I do the request in a browser I get the following response

<d:RetrieveMaxHit xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:type="CRM_OPPORTUNITY.MaxHit">
<d:MaxHitNumber>100</d:MaxHitNumber>
<d:ActionResult>X</d:ActionResult>
</d:RetrieveMaxHit>

I hope someone can help me grasp why resp.data does not contain the data returned from the sevice? What am I missing?

2
RetrieveMaxHit is a functionImport on the service. Can that have any impact? I tried calling with oModel.callFunction() instead of oModel.read(). Same result --> resp.data is undefined - Morten Milbak
I'm voting to close this question as it's missing details to reproduce the issue. And the current accepted answer is not only misleading but also encouraging use of deprecated API and anti-patterns. - Boghyon Hoffmann

2 Answers

0
votes

Should you not use

oModel
        .read(
            "**/**RetrieveMaxHit",

Did you also check on your gateway system with /IWFND/TRACES that the correct service is invoked and is indeed giving back the correct feedback?

-2
votes

Problem was that the oDatamodel had to be instantiated with JSON set to TRUE. Apparently the response in XML returned when calling the FunctionImport was not able to be correctly mapped into the response.Data.

var parameters = {
    json: true
};

var oModel = new sap.ui.model.odata.ODataModel("http://XXXXX:XXXX/sap/opu/odata/sap/CRM_OPPORTUNITY/", parameters);