cancel
Showing results for 
Search instead for 
Did you mean: 

Quering an OData Endpoint with a timestamp does not work in CDS

jensniemeyer
Participant
0 Kudos
139

Hi,

I wrote a CAP service which is communicating with C4C via OData.

In the service I  want to read all BusinessPartner with a certain ChangeDate.

The pure OData Call will be:

https://myXXXXX.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/BusinessPartnerCollection?$filter=EntityLastChangedOn ge datetimeoffset'2024-01-10T06:35:38.1533450Z'

In my service I wrote:

const c4cBuPaService = await cds.connect.to("c4c_bupa");
const allBuPa = await c4cBuPaService.run(SELECT(["AccountID", "ContactID"]).from("ContactCollection").where(`ChangedOn > datetimeoffset'${myDate.toISOString()}'`.toString()));
        This leads to an error, because with CDS icompiles the statement to
....$filter=EntityLastChangedOn ge 'datetimeoffset'2024-01-10T06:35:38.1533450Z''

So, the datetimeoffset is enclosed in quotation marks.
I tried all various options to change it, no success.

So my question would be: How to query a timestamp in CDS?

Thanks
Jens

 

 

 

View Entire Topic
catano
Active Participant
0 Kudos

Hi @jensniemeyer ,

Have you tried the SQL-like fluent API mentioned in the documentation?

I'm thinking something like this:

 

SELECT(["AccountID", "ContactID"]).from("ContactCollection").where({ ChangedOn: { '>': myDate } })

 

Could you check if this could work?

Rgards,

Peter