cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Make a virtual element available as filter

robbewuyts
Explorer
0 Likes
8,975

Hi,

I Successfully added a virtual element to my CDS, now I noticed this field is not available as filter. Is there anyway I can make this available?

I currently have the annotation @ObjectModel.virtualElementCalculatedBy active. This works fine.

When I combine it with @ObjectModel.filter.transformedBy, I get a dump: CX_SADL_DUMP_APPL_MODEL_ERROR.

I implemented both methods MAP_ATOM and CALCULATE.

I can find an example where a combination is used: Adding Annotations for Virtual Elements | SAP Help Portal

regards,

Robbe

Accepted Solutions (0)

Answers (1)

Answers (1)

amangarg1
Contributor

Hi Robbe,

To make the field available in filter, you can use the annotation ui.selectionfield.

However, since the field in discussion is a virtual field, filtering won't work out of the box. You can try implementing filter exit referring below blog. I have tried and this works perfectly fine for me

https://blogs.sap.com/2020/01/16/filtering-on-association-property-in-fiori-element-app-via-abap-cds...

In case this doesn't work, I would request you to share the exit class code and the error screenshots.

Thanks,

Aman Garg

robbewuyts
Explorer
0 Likes

Hi,

In the example a virtual element is used to filter, but it's not calculated. My virtual element is calculated, but I also want to be able to filter on this field.

The calculation works fine, only the filtering gives me a dump.

regards,

Robbe

amangarg1
Contributor
0 Likes

Hello,

in both the cases, the field in discussion is not a persisted field, so behaviour should be same. In my case, it was a calculated field, and I could filter it this way. The only difference is I used keyword VIRTUAL (in front of CAST keyword) instead of @objectMode.virtualElement: true. Although, these two are pretty much the same but you can give this a try.

Also, does control reach the map_atom method or does it dump before this? An error screenshot would help in understanding the problem much better.

Thanks,

Aman Garg

robbewuyts
Explorer
0 Likes

Hi,

Not sure what you mean with the keyword VIRTUAL.

When I uncomment the transformedBy line, I am able to filter on Authorised, but it dumps:

amangarg1
Contributor
0 Likes

Hi,

This is what I mean by keyword virtual:

Could you try this way?

Also, as you say that filtering works but it dumps, this might be because you have used virtual elements in Interface layer. Could you try creating a projection view on top of your main(interface) CDS view and use virtual key word instead of annotation. I hope then it should work.

Thanks,

Aman Garg

robbewuyts
Explorer
0 Likes

Hi,

I already tried this in the meantime, same result.

When the query is executed, I enter the MAP_ATOM method, but before we get to the calculate method, the dump occurs.

regards