cancel
Showing results for 
Search instead for 
Did you mean: 

Error When Filtering LocalTime with value null - SAP Cloud SDK

04-26-2021 7:01 PM
idefix Participant
41497 views 4 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

My API-Call:


https://apisalesdemo8.successfactors.com/odata/v2/EmployeeTime?$select=userId,timeType,timeTypeNav/e...

The result is:


I am using odata-generator maven plugin to generate classes from edmx file.

And this is how I do the query in code:

        final List<EmployeeTime> employeeTimes =
                new DefaultEmployeeTimeService().withServicePath("/odata/v2/")
                .getAllEmployeeTime()
                .select(
                    EmployeeTime.USER_ID, 
                    EmployeeTime.TIME_TYPE, 
                    EmployeeTime.EXTERNAL_CODE, 
                    EmployeeTime.START_DATE, 
                    EmployeeTime.START_TIME, 
                    EmployeeTime.END_DATE, 
                    EmployeeTime.END_TIME)
                .top(10)
                .executeRequest(httpDestination);

I would like to filter the start date with value null. So my code is:

 final List<EmployeeTime> employeeTimes =
                new DefaultEmployeeTimeService().withServicePath("/odata/v2/")
                .getAllEmployeeTime()
                .select(
                    EmployeeTime.USER_ID, 
                    EmployeeTime.TIME_TYPE, 
                    EmployeeTime.EXTERNAL_CODE, 
                    EmployeeTime.START_DATE, 
                    EmployeeTime.START_TIME, 
                    EmployeeTime.END_DATE, 
                    EmployeeTime.END_TIME)

                 .filter(EmployeeTime.START_TIME.eq(null)
 
                .top(10)
                .executeRequest(httpDestination);

but I got an error:

com.sap.cds.services.impl.ContextualizedServiceException: Cannot invoke "Object.getClass()" because "value" is null (service 'EmployeeTimeService', event 'READ', entity 'EmployeeTimeService.EmployeeTime')

Does it not support filter with value null?

This is the code in oDataType.class (com.sap.cloud.sdk.odatav2.connectivity) which caused the problem.

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

former_member186608
Active Participant
0 Likes

Hi Edwin,

SAP Cloud SDK 3.45.0 fixes this issue.

Refer to the release notes for further reference.

Kind regards

Marco Dahms

idefix
Participant
0 Likes

Thank you Marco, it works!

Answers (2)

Answers (2)

idefix
Participant
0 Likes

Thank you Alexander. The workaround works!

0 Likes

Hi Edwin,

We're investigating this case. In the meantime, there's a workaround to use an unchecked, custom filter expression from our OData Client API:

.filter(
  new UncheckedFilterExpression<>(
    FieldReference.of(EmployeeTime.START_TIME.getFieldName())
      .equalTo(Expressions.Operand.NULL)))

If other values than null are possible you can use

Expressions.createOperand( yourValue )

instead of

Expressions.Operand.NULL

Kind regards

Alexander