cancel
Showing results for 
Search instead for 
Did you mean: 

How to apply default filter on service entity using low code SAP Productivity Tools

renejurmann
Participant
0 Kudos

Hi experts,

I have created a Low-Code project in Business Application Studio using SAP Productivity Tools. I defined two tables in the schema.cds as well as a service.cds and Fiori Elements UIs.

Now I want to apply a predefined filter (or data restriction) within the service or schema either using logic or annotations.

In SAP CAP I could add a filter or restriction by creating a filter in the BEFORE READ event, by removing certain values in ON READ or by adding a restrict annotation for all or specific users.

But using SAP Productivity Tools the restrict annotation does not seem to work:

@restrict: [{"grant":["READ"],"to":["authenticated-user"],"where":"deletionIndicator=false"}]

At least I still see all entries.

When trying to add "code" to a service logic the appearing code field is quite small, not handy and has no real code inspector. However, I added following code for the BEFORE READ event:

context.request.query.SELECT.where.push({ref: ["deletionIndicator"]})
context.request.query.SELECT.where.push("=")
context.request.query.SELECT.where.push({val: false})

This is working. But I suspect there must be a better way to restrict/filter the values for an entity.

I explicitly do not want to apply a default filter within the Fiori Elements UI but within the service implementation (due to various reasons).

How can I achieve this using tha SAP Productivity Tools?

regards

René

View Entire Topic
xinye
Advisor
Advisor
0 Kudos

Hello René,

Regarding the `@restrict` annotation, which is relevant to the authorization, so it can be verified after deployment. Would you please give it a try? It should work.

Btw, I can also reproduce the same issue with you in the local env when preview the service data, it looks this annotation is ignored in local env.

In terms of the customization on service side via application logic, what your done looks quite solid to be compatible with various use cases, e.g. access from OData URI path or from UI app. No better suggestion from my side. But one information for your reference is, the custom code line control within application logic visual editor has been enhanced which will be public available very soon along with next BAS's Productive Tool release. A new OSS JavaScript source editor has been introduced to replace the original html native input. Hopefully it could make your implementation more easier.

Regards,

Xin

renejurmann
Participant

Hi Xin,

thanks for the answer. Yes, after deployment the "@restrict" annotation is working. It would be nice if this annotation could be supported in local env as well (I know that this is challenging as the annotation requires a user authentication an in local env this is most likely the developer only)

regards

René