Hybris enumtype static Vs dynamic

In Hybris, we can declare two type of enum, Static and Dynamic. Which basically differ by dynamic attribute (dynamic="false" and dynamic="true").
In simple words, I can say static enum(dynamic="false") is generated as the Java enum. In which list of values can only be changed during compilation time by changing the items.xml. In case of the dynamic enum(dynamic="true") we can change(add/remove) its values at runtime using hmc or Impex.

Regardless of an Enum type(Static/Dynamic), all its values get stored in enumerationvalues table. You can fetch all values using below flexible query.

select * from {enumerationvalue}


Static Enum:

    <enumtype code="FixedValueType" autocreate="true" generate="true">
        <value code="value1"/>
        <value code="value2"/>
    </enumtype>
By default, the dynamic attribute is false(dynamic="false"). You can declare static enum like above. In case of the static enum, we are not allowed to add/remove value at runtime. It throughs error like
If you want to add a new value to this type you have to define the enum type as non dynamic at items.xml (needs system update afterwards).

Dynamic Enum:

    <enumtype code="OrderStatus" autocreate="true" generate="true" dynamic="true">
        <value code="CREATED"/>
        <value code="ON_VALIDATION"/>
        <value code="COMPLETED"/>
        <value code="CANCELLED"/>
    </enumtype>
If you want to have an enum which can be changed runtime, you should declare it with dynamic="true".

Switching between enum types is possible at runtime. We need to change dynamic flag and then update the system.
Author Image

Ankitkumar Patel

Sr. SAP Hybris consultant, having 15+ years experience in SAP Commerce Cloud (Hybris), SAP Spartacus. Extensive experience in SAP Hybris development, third-party integrations, project architecture and design... Read more

Comments

  1. how to add/remove enum values at runtime for dynamic enum

    ReplyDelete
    Replies
    1. You can add it through HMC/Backoffice. Go to type, search for your enum type lets say "OrderStatus", open it and there you can see all values, now right click to see all option(edit/remove/create).

      Delete
  2. We are able to delete from HMC but it is giving error while saving "The item could not be saved due to the following errors: cannot delete uneditable EnumerationValue"

    ReplyDelete

Post a Comment

Popular posts from this blog

Hybris flexible search query examples

How to remove or update all data records in Hybris?

How to Install temporary Hybris license?