Skip to Content

Invoke multiple oData expand with date parameter in Entityset

Hello Expert,

I have the following oData url

/sap/opu/odata/ABC/XYZ_SRV/EMP_DETAILSSet(Empid='342123',Begdate=datetime'2011-03-01T00:00:00',Endda=datetime'9999-12-31T00:00:00',HAFId=' ')?$expand=NAVTODETAIL,NAVTOPROFILE,NAVTOREPORTEES

Here, I have multiple expand to be done in one call with some input parameters within the entityset (where Begdate and Enddate are date).

Can you please help me with the code to invoke the above service from SAPUI5 controller?

I tried the following, but did not work.

			oBackEndModel.read("/EMP_DETAILSSet", {
				context: {
					"Empid": "342123",
					"Begdate": new Date(),
					"Enddate": dEndDate,
					"HAFId": ""
				},
				urlParameters: {
					$expand: "NAVTODETAIL,NAVTOPROFILE,NAVTOREPORTEES"
				},
				success: jQuery.proxy(this._fGetDetailsSuccess, this),
				error: jQuery.proxy(this._fBackEndInvocationError, this)
			});

Regards,

SAP Learner

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Jun 08, 2018 at 10:25 AM

    as i understand, you need to format the date before send to backend, and read URL itself can have those parameters, no need to define "context"

    below code may help,

    var oFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({ 
      pattern: "yyyyMMdd THH:mm:ss",
      style: "medium"
     });
    var oDate = new Date();
    var sDate = oFormat.format(oDate);
    
    var sPath = "/EMP_DETAILSSet(Empid='342123',Begdate=" + sDate + ",Endda=" + sDate + ",HAFId=' ')";
    
    oBackEndModel.read(sPath, {
    urlParameters: {
    		$expand: "NAVTODETAIL,NAVTOPROFILE,NAVTOREPORTEES"
    		},
    .....

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Akhilesh,

      I have tried the following as per your suggestion.

      var oFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({ 
        pattern: "yyyyMMddTHH:mm:ss",
        style: "medium"
       });
      var oDate = new Date();
      var sDate = oFormat.format(oDate);
      var sServicePath = "/EMP_DETAILSSet(Empid='342123',Begdate='"+sDate+"',Enddate='"+sDate+"',HAFId='')";
      console.log(sServicePath);
          var oBackEndModel = that.getModel("backEndModel");
           oBackEndModel.read( sServicePath , null, null, true, function(){
                  alert("Read success");},function(a,b,c){
                  alert("Read failed");});

      However resulted in error: failed400,Bad Request,{"error":{"code":"005056A509B11EE3A3CE356766C11B1C","message":{"lang":"en","value":"Invalid URI segment '38:40',Enddate='20180612T16:38:40')'"}

      console.log printed the following string which I have used as oData input:

      /EMP_DETAILSSet(Empid='342123',Begda='20180612T16:38:40',Enddate='20180612T16:38:40',HAFId=' ')

      Regards,

      SAP Learner

  • Jun 11, 2018 at 05:05 AM

    Hello,

    Can someone please help me here?

    Please note that I have also tried the following where date is in yyyy-mm-dd format and datetime is suffixed at the beginning of the date

    			var oFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({
    				pattern: "yyyy-MM-ddTHH:mm:ss",
    				style: "medium"
    			});
    			var dBegDate = new Date();
    			dBegDate.setHours(0,0,0,0);
    			var sBegDate = oFormat.format(dBegDate);
    
    
    			var dEndDate = new Date();
    			dEndDate.setYear(9999);
    			dEndDate.setMonth(11);
    			dEndDate.setDate(31);
    			dEndDate.setHours(0,0,0,0);
    			var sEndDate = oFormat.format(dEndDate);
    
    
    		var sPath = "/EMP_DETAILSSet(Empid='50160458',Begdate=datetime'" + sBegDate + "',Enddate=datetime'" + sEndDate + "',HAFId=' ')?$expand=NAVTODETAIL,NAVTOPROFILE,NAVTOREPORTEES&$format=json";
    			oBackEndModel.read(sPath, {
    				success: jQuery.proxy(this._fGetDetailsSuccess, this),
    				error: jQuery.proxy(this._fBackEndInvocationError, this)
    			});
    

    However, gateway has returned me the error message: The request URL or the metadata definition is incorrect.

    Regards,

    SAP Learner

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Akhilesh,

      Yes. They are.

      Following url returned result in Gateway client without any issues..

      /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

      Then I tried the following from SAPUI5 controller

      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)});

      This returned the following error in browser console:

      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 (https://service.sap.com/sap/support/notes/1797736)"}}}}

      Error info in gateway system says: The request URL or the metadata definition is incorrect.

      I am clueless on what the issue is.. Can you please suggest

      Regards,

      SAP Learner

  • Jun 11, 2018 at 04:10 PM

    just pass the date as JSON format...

    json format of date is YYYY-MM-DDTHH:MM:SS

    run the below code in chrome console..


    date-tojson.png (14.0 kB)
    Add comment
    10|10000 characters needed characters exceeded

    • 1. Read operation documentation (your code looks ok)

      2. For date input parameter, you can open standard My Inbox application and then apply filter on date values. Whatever format is passed for $filter, you can check in Networks tab and use same.

      3. Multiple Expand also looks correct. Put an external breakpoint and see.

  • Jun 13, 2018 at 07:11 AM

    Can someone please help me here

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 18, 2018 at 04:46 AM

    Hello..

    I am yet to get a solution here. Can anyone help me please..

    Add comment
    10|10000 characters needed characters exceeded