0

I am confused on the date format to be used while invoking OData read operation where parameters are mentioned within entityset brackets. Would be great if you can paste your answer against each

  1. How to use ODataModel's read() method if we have values to be passed within the entity set parameters?

    var sPath ="/EMP_DETAILSSet(Empid='50160458'/*, ...*/)";
    oBackEndModel.read(sPath, {
      success: this._fGetDetailsSuccess.bind(this),
      error: this._fBackEndInvocationError.bind(this)
    });
    

    Is this the approach to be followed? Or do we have any other approach?

  2. How to set date as entity set key parameter with OData? Please correct the below code snippet (which gives me bad request error at runtime) where dBegDate and dEndDate are JS standard date objects.

    var sPath ="/EMP_DETAILSSet(Empid='50160458',Begdate="+ dBegDate.toJSON() + ",Enddate=" + dEndDate.toJSON() + ",HAFId=' ')";
    oBackEndModel.read(sPath, {
      success: this._fGetDetailsSuccess.bind(this),
      error: this._fBackEndInvocationError.bind(this)
    });
    
  3. How to execute multiple expand operation along with the entityset parameters mentioned above? Please fix the error in the below code as it is not working for me.

    var sPath ="/EMP_DETAILSSet(Empid='50160458',Begdate="+ dBegDate.toJSON() + ",Enddate=" + dEndDate.toJSON() + ",HAFId=' ')";
    oBackEndModel.read(sPath, {
      urlParameters: {
        $expand: "NAVTODETAIL,NAVTOPROFILE,NAVTOREPORTEES"
      },
      success: this._fGetDetailsSuccess.bind(this),
      error: this._fBackEndInvocationError.bind(this)
    });
    

Further updates

I have followed the suggestion b Sunil. sPath looked as follows at runtime:

"/EMP_DETAILSSet(Empid='50160458',Begdate=datetime'2014-03-11T14:49:52',Enddate=datetime'9999-12-31T14:49:52',HAFId=' ')"

When I tried this, it gave me the following error:

2018-06-13 10:56:31.872300 The following problem occurred: HTTP request failed404,Not Found,{"error":{"code":"005056A509B11EE1B9A8FEC11C21D78E","message":{"lang":"en","value":"Resource not found for the segment '49:52',Enddate=datetime'9999-12-31T14:49:52',HAFId=''."},"innererror":{"transactionid":"5B20F78A93457852E10000000ACD4014","timestamp":"20180613052610.2725590","Error_Resolution":{"SAP_Transaction":"Run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details","SAP_Note":"See SAP Note 1797736 for error analysis ..."}}}}

Do you know why?

Please note that the following URL works fine and returned the result when executed from SAP Gateway Client: /sap/opu/odata/XXX/YYYY_SRV/EMP_DETAILSSet(Empid='50160458',Begdate=datetime'2014-03-11T14:49:52',Enddate=datetime'9999-12-31T14:49:52',HAFId=' ')?$expandNAVTODETAIL,NAVTOPROFILE,NAVTOREPORTEES&$format=json

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
SAP Learner
  • 61
  • 4
  • 17
  • The issue is creating the `sPath` manually which is error-prone. In order to create the key string reliably in accordance with the OData V2 service's metadata, [`v2.ODataModel#createKey`](https://stackoverflow.com/a/47016070/5846045) can be used, as mentioned in the linked Q&A. – Boghyon Hoffmann Jan 30 '23 at 07:41

1 Answers1

0
  1. First thing is to check, what is the primitive type defined in you SAP Netweaver gateway. Most probably, it will beEdm.DateTime. You can get this info using $metdata call on service.

  2. OData has standard representation of Edm.DateTime

datetime'yyyy-mm-ddThh:mm[:ss[.fffffff]]'

NOTE: Spaces are not allowed between datetime and quoted portion. datetime is case-insensitive

Example : datetime'2000-12-12T12:00'

If its JSON Format representation,

Example: "FlightDate": "/Date(1354665600000)/"

It should look something like:

var sPath = "/EMP_DETAILSSet(Empid='50160458',Begdate=datetime'2014-03-11T14:49:52',Enddate=datetime'2014-03-11T14:49:52',HAFId = ' ')";
oBackEndModel.read(sPath, {
    urlParameters: {
        $expand: "NAVTODETAIL,NAVTOPROFILE,NAVTOREPORTEES"
    },
    success: jQuery.proxy(this._fGetDetailsSuccess, this),
    error: jQuery.proxy(this._fBackEndInvocationError, this)
});
Sunil B N
  • 4,159
  • 1
  • 31
  • 52
  • After following your approach, I have added further updates right beneath my initial question. May be, I am not updating the forum in the right way as I am novice here. Please check the details once – SAP Learner Jun 13 '18 at 12:23
  • Try encoding the path before invoking create on oData., if things work from SAP gateway, it should definitely work from browser call. – Sunil B N Jun 13 '18 at 18:16
  • Can you please provide with corresponding code snippet for the above example? I have used the method encodeURIComponent() for the string which I have constructed. However, it did not work!! Please note that I have another service where date input is not there as entity set parameter. That service works fine while using oModel.read(). Facing Issue only when I try to invoke oData where dattime paramter is there as entityset input. That is why I started suspecting the date input parameter of /EMPDETAILSet. Can you share the documentation to invoke entity set with datetime input parameter. – SAP Learner Jun 18 '18 at 10:30