cancel
Showing results for 
Search instead for 
Did you mean: 

Setting default value for property on service level in CAP

EMueller
Explorer
0 Kudos

Dear community,

I have a question regarding SAP CAP development.

On service level, I'm adding a property to my entity as explained here: Adding computed fields

entity Models as select from db.Models {
     *,
     null as test: Boolean }

How can I set a default value for this new property?

In this case, I would like my property "test" to be true.

Thanks and best regards,

Elias

Accepted Solutions (1)

Accepted Solutions (1)

johannesvogel
Advisor
Advisor
0 Kudos

Did you try:

entity Models as select from db.Models {
     *,
     true as test: Boolean }

This should create the underlying database view with true as default. Or in which situations do you want the default applied?

EMueller
Explorer
0 Kudos

Yes I tried that, however it still puts the value to null.

johannesvogel
Advisor
Advisor
0 Kudos

Which request do you send?

I have tried it using the Node.js runtime and a simple GET request to that entity and for me it works.

EMueller
Explorer
0 Kudos

Ok, I removed the @cds.persistance.exists from my Entity and tried the same thing using mock data.

It worked!

It seems like the issue is due to the data fetching from a remote server.

Thanks for your help.

BR,

Elias

johannesvogel
Advisor
Advisor
0 Kudos

If you fetch the data from somewhere else you must set the computed value yourself in your custom handler 🙂

Answers (0)