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(
Regardless of an Enum type(Static/Dynamic), all its values get stored in enumerationvalues table. You can fetch all values using below flexible query.
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.
how to add/remove enum values at runtime for dynamic enum
ReplyDeleteYou 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).
DeleteWe 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