cancel
Showing results for 
Search instead for 
Did you mean: 

Error while Passing date parameters in Custom build API

0 Kudos
1,284

Hi Experts,

I have a CDS View which is EXA (External API) and i made communication setup for that CDS View.

After that i have tried to query it using postman. Got the below error.

Error:

In the context of Data Services an unknown internal server error occurred

Note: CDS View contains From date , todate parameters. I have the same kind of CDS view which has the same fields and Parameters also used for communication scenario.

$metadata loaded successfully.

But tried with the CDS view which does not have Parameters its works.

Analysis:

After 2102, we have some Define parameter option in Custom CDS Views App . In Datasources tab we have Parameter icon i clicked it. its opened. But its assigned properly.

Url: https://myxxxx-api.s4hana.ondemand.com/sap/opu/odata/sap/YY1_XYZ_CDS/YY1_XYZ(P_FromPostingDate=datetime'2021-02-01T00:00',P_ToPostingDate=datetime'2021-02-02T00:00')/Results

Please suggest if you have any idea.

Thanks,

Lingaraj

View Entire Topic
Jerry_Lowery
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Lingaraj,

Can you check the metadata for your parameter and confirm the type is like Edm.DateTime, for example. If it is not, your datetime'...' statement will not work.

<Property Name="SalesOrderDate" Type="Edm.DateTime" Precision="0" sap:aggregation-role="dimension" sap:display-format="Date" sap:required-in-filter="false" sap:label="Document Date"/>

Another way to do it is to add the posting date to your list of elements and use the filtering native to OData.

For example, I have a custom CDS view with SalesOrderDate as an added element from the datasource

and I use the filtering like this:

{{url}}/sap/opu/odata/sap/YY1_Z_SALES_ORDER_EXTRACT_CDS/YY1_Z_SALES_ORDER_EXTRACT?$filter=SalesOrderDate gt datetime'2020-05-31T00:00:00'

in your case you could use a combination of filtering including lt and gt (less than and greater than).

Thank you,

Jerry