Skip to Content
author's profile photo Former Member
Former Member

Changing default value of attribute on business logic

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?

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 14, 2016 at 05:54 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 14, 2016 at 09:01 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 14, 2016 at 10:04 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.