cancel
Showing results for 
Search instead for 
Did you mean: 

Changing default value of attribute on business logic

Former Member
0 Kudos

Hi all,I am a in Hybris and had a doubt.I am working on a project and it required to have an attribute such that it's default value is set dynamically but the value can be modified from hmc.Normal attributes are static so they won't allow business logic.Will dynamic attributes work here as I am not sure whether they can be modified from hMC?

Former Member
0 Kudos

By the way, I noticed that you're asking a lot of questions. Please make sure to vote answers and mark them as accepted, when your problems is solved.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Your use case is exactly what the Init Defaults Interceptor was made for.

The Init Defaults Interceptor is called when a model is filled with its default values. This happens either when it is created via the modelService.create method or when the modelService.initDefaults method is called. You can use this interceptor to fill the model with additional default values, apart from the values defined in the items.xml file

Make sure you're registering the interceptor correctly.

Former Member
0 Kudos

@Christian,I made the interceptor and registered it.But it's overridden method is not being called,when the user logs into hMC.How to ensure that it should be called,because the modelService.create() method or the modelService.initDefaults() is not called?

Former Member
0 Kudos

@Reachit: You mean onInitDefaults(..) is not called? How does your spring config look like?

Former Member
0 Kudos

@Christian,after making an interceptor and overriding the onInitDefaults( ) method,I made an entry for the interceptor bean and interceptor mapping bean in the file extensionName-spring.xml.Am I doing this right so that this is called when user views this in hMC?

Former Member
0 Kudos

Could you show us the interceptor bean and mapping from your spring.xml?

Former Member
0 Kudos

@Christian,in the onInitDefaults( ) method,the different fields for the object are coming out to be null.What can be the reason?

Former Member
0 Kudos

It's difficult to guess. Can you create a new question including your interceptor code?

0 Kudos

Hi Rachit,

You can set dynamic value for an attribute, but you CANNOT change its value via hMC, i.e modified value is not persisted

Regards, Chaitu.

Former Member
0 Kudos

Thanks chaitu.But is there any other solution for it?

0 Kudos

you need an attribute with default value during creation and u need that value to be set later via hMC ??

Former Member
0 Kudos

Hi Rachit,

Yes you can create a dynamic attribute and write your desired business logic inside the DynamicAttributeHandler class.

For reference, please check the link below: https://wiki.hybris.com/display/release5/Dynamic+Attributes

Former Member
0 Kudos

Hi Sourav,thanks a lot.But if this attribute is modified using hMC,will it reflect in the model or the default value.