cancel
Showing results for 
Search instead for 
Did you mean: 

Default value for an attribute in a type in the *core-items.xml

datacol
Explorer
0 Kudos

Hello everyone,

I would like to know if it is possible to set a default value for a specific attribute when you declare an item in the *core-items.xml. In particular, I need to specify a default string value. I see that I can do that for primitive types, but I can't find any answer for no primitive types. I tried to write it in the following way as specified here https://stackoverflow.com/questions/63314600/how-to-set-default-value-for-a-map-attribute-of-an-item...

<attribute generate="true" autocreate="true" qualifier="robotsDescription" type="localized:java.lang.String">

<persistence type="property"/>

<modifiers read="true" write="true" search="true" initial="true" optional="true"/>

<defaultvalue>"noindex,nofollow"</defaultvalue>

<description>Descrizione Robots per indicizzazione pagina prodotto</description>

</attribute>


It seems that the default value declaration does not work since I can't see any values in the backoffice. I'm using SAP Hybris 6.5 version.


Thanks all for any kind of support

View Entire Topic
StefanKruk
Active Participant

You could use an InitiDefaultsInterceptor which will set the Values when you do a

modelService.create(ModelItem.class);

or

ModelItem item = new ModelItem();
modelService.initDefaults(item);

See: https://help.sap.com/docs/SAP_COMMERCE/d0224eca81e249cb821f2cdf45a82ace/8bfbf43e8669101480d0f060d79b... for the whole Life Cycle of a Model.

(The Documentation is for the latest version, but it didn't change since 6.5, so the life cycle is still the same)

datacol
Explorer
0 Kudos

As far as I understood, it works when you create a new "item". In my case I am searching a way to do it for already created "item". I need this because I extended a model with a new attribute and It would be great If I can set a default value.

StefanKruk
Active Participant
0 Kudos

In this case you need to create a "PrepareInterceptor" in which you check if you need to set additional Values or just update the existing Values via Impex.

datacol
Explorer
0 Kudos

Yes, the impex was an idea I also had. I will try the PrepareInterceptor" to see how it works. Anyway, thanks for the help.