cancel
Showing results for 
Search instead for 
Did you mean: 

Gateway Service annotations - valuelist default value

michael_smithe5
Participant
0 Kudos

I have a datafield Country on a custom entity Customer. I have added the valuelist annotation to that field and made it fixed-values which all appears to work. However, when I create a new customer, I want the country to default to 'US'. Is there a way to set the default value in the DEFINE method of the MPC_EXT class or do I have to extend the Object Page of my List Report Fiori Elements application to set the default country?

Accepted Solutions (0)

Answers (2)

Answers (2)

junwu
Active Contributor
0 Kudos

what is your architecture?

i tried with cds+bopf, you just have to add a determination to set the default value, it can be easily done.

if you use odatamodel createentry, you can set the default value in the parameter, I didn't try.

michael_smithe5
Participant
0 Kudos

We are on a HANA 2.0 system, but we chose to use strictly Gateway Services without CDS (although I think we will eventually move to using CDS). Sadly, I could not find a way to accomplish pre-populating default values with the generated object page, so I chose to create my own UI5 application from scratch using a smart table and a smart form where I can do the necessary coding in the controller.

Joseph_BERTHE
Active Contributor
0 Kudos
michael_smithe5
Participant
0 Kudos

I had looked at the first link and attempted to override getPredefinedValuesForCreateExtension(), but it was not clear from the documentation where that code needed to be - in the Component.js or in a Controller Extension?? Also, it appeared that it would only work with the createWithFilter setting, not the standard create screen. If you have seen a working example of this override, please point me to it.

I also attempted setting the metadata property for default value in the DEFINE method of my MPC_EXT class (I'm not using CDS). That metadata property doesn't appear to do anything. Here is the code I used for that:

me->model->get_entity_type( 'Customer' )->get_property(
'Country' )->set_default_value( lv_def_country ).

Joseph_BERTHE
Active Contributor
0 Kudos

I didn't try the first link, in one project of mine, I wanted to do the same but with Field Control by default. The solution I found (it is a workarount) was to do a read() query with a specific key to return all default values during the creation process.

The second link is after looking at more deeply is to have default value during the search. So in your case it is not relevant.