SAP / cloud-sdk-js

Use the SAP Cloud SDK for JavaScript / TypeScript to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
161 stars 53 forks source link

Null filter for datetime field not supported #4724

Closed Florin1335BP closed 1 month ago

Florin1335BP commented 1 month ago

Hi,

I was trying to apply a not null filter for a datetime field, through the oData v2 client API and I'm getting an error, it looks like the value must be a moment date object only. DATETIME_FIELD.notEquals(null) -> Error: Cannot read properties of null (reading 'toISOString') in @sap-cloud-sdk\odata-v2\dist\de-serializers\default-de-serializers.js Is there a way I can apply such a filter or is this not supported?

deekshas8 commented 1 month ago

Hi @Florin1335BP ,

Thanks for raising this. I believe there is an issue in how we serialize Edm.DateTime fields for the URI. I'll create a ticket to investigate and fix this. In the meantime, you could try to use custom de-serializer to add the null filter. You can find the docs here

Maybe adding a null check like:

'Edm.DateTime': {
    deserialize: deserializeToMoment,
    serialize: serializeFromMoment,
    serializeToUri: value =>
      value == null ? 'null' : `datetime'${value.toISOString().replace(/Z$/, '')}'`
  },
Florin1335BP commented 1 month ago

Hey @deekshas8, I tried that and it's working fine now. Looks like I can get away with defining only serializeToUri since I'm doing a GET request with executeRaw, so no need for deserialization and serialization. Since the solution is documented I'll go ahead and use it, thank you very much!