Runtime change of enum field


I have an Entity (call it WorkItem) which has a Status field, an Enumeration.

Thing is I have multiple types of WorkItem which are exactly the same on all aspects (fields, UI, …) EXCEPT for the Status Enumeration.

The type of the WorkItem is indicated by an association to a WorkItemType

Some WorkItem types have 3 statusses, others have 5, …

So, I think I have those options ahead of me:
a) Use inheritance on the WorkItem to go changing the StatusEnumeration. This seems a bit overkill as I’d have to add lots of code around a discriminator field and would end up with a total mess. Also adding new WorkItem types would require code changes.

b) Use a method on the Enumeration that returns a List of the avaiable Statusses for a WorkItemType. I would avoid importing WorkItem from the Enum by passing a String id instead of the WorkItemType instance. That would need manual steps on the UI to display the valid statusses. New types would just need changes on the Enumeration.

But I think, what would be nicest would be Option c): Override the Enumeration directly in WorkItem when using the record. I would have different StatusEnumeration child classes for each type and then, somehow, when using the WorkItem the appropiate child class would be on the Status field. – This way I do not need to do anything outside the Entity: all UI elements, rest etc would pick the right Enumeration as long as the Entity.workItemType is properly set.

Of course, there’s option d) store this on a WorkItemStatus Entity and use an associacion with a filter but, again, needs lots of things in a lot of places for something quite simple.

Thous WorkItemType might change overtime, the kinds of Status Enumerations I need is quite short (maybe 5) as most Types share the same enumeration.

Is Option c) feasible? Can someone point me in the right direction?


I think the dynamic attributes and categorized entities may be useful for you.


Thanks for the tip Natalia.
For completeness of this thread:

I’ve been playing around with the dynamic attributes as suggested.
Recap: I would have a WorkItemType Entity with a “possibleStatusses” field which would later be used by WorkItem.status field – This is currently an Enum in WorkItem.status.

As per your suggestion I see two alternatives:
a) WorkItemType does not have a “possibleStatusses”. WorkItem has a Category that defines the statusses. My code can then categorise WorkItem according to the WorkItemType
b) WorkItemType is categorised, then WorkItem has a String field to store the status and uses the WorkItemType category to get the possible statusses.

Option a) is what is most straight forward, but my concern is that I would bloat the CategoryAttributeValue table as there would be thousands of categorised WorkItem. I understand, from the code, that there is one single table for all attribute values of all categorised entities.

Option b) is which looks more performant but after some messing around I still have not found my way around it. I looked around the RuntimePropertiesFrame code (looks to be the best place to see a real example of working code around Category, CategoryAttribute & CategoryAttributeValue) but it looks to me that the mess of code I’d need to make b) work would not compensate the performance loss compared to a).

So, for now I will go with a) by storing a reference to the appropiate Category to apply to the WorkItem inside the WorkItemType, then when creating a WorkItem I would just apply the Category and be done with that.

Re. b) the documentation on DynamicAttributes is currently very poor. There’s a definition, and how to use them in the Generic UI but no detailed code examples I could find – maybe wishlist item: extend the Dynamic Attributes documentation or publish some example on github :slight_smile:


Hi Marc,

I have some doubts about using dynamic attributes in your case. If I understand you correctly, you don’t need additional attributes for your entities, you just need to filter some reference values according to the instance type defined by WorkItemType.
If you make the Status enumeration a regular entity stored in the database, the WorkItem.status attribute becomes a reference. Add a reference to WorkItemType to the Status entity too. When loading options for WorkItem.status in UI, filter them by the current type of the WorkItem.

1 Like

This is probably the simplest way to achieve that.
Thank you !