Enumerations
Enumerations define a fixed set of named values. They are used as attribute types to restrict a field to a specific list of options.
CREATE ENUMERATION
[/** <documentation> */]
CREATE ENUMERATION <Module>.<Name> (
<value-name> '<caption>' [, ...]
)
Each value has an identifier (used in code) and a caption (displayed in the UI):
/** Order status enumeration */
CREATE ENUMERATION Sales.OrderStatus (
Draft 'Draft',
Pending 'Pending Approval',
Approved 'Approved',
Shipped 'Shipped',
Delivered 'Delivered',
Cancelled 'Cancelled'
);
Using Enumerations in Attributes
Reference an enumeration type in an attribute definition with Enumeration(Module.Name):
CREATE PERSISTENT ENTITY Sales.Order (
Status: Enumeration(Sales.OrderStatus) DEFAULT 'Draft',
Priority: Enumeration(Core.Priority) NOT NULL
);
The default value is the name of the enumeration value (not the caption). The fully qualified form is preferred:
-- Fully qualified (preferred)
Status: Enumeration(Sales.OrderStatus) DEFAULT Sales.OrderStatus.Draft
-- Legacy string literal form
Status: Enumeration(Sales.OrderStatus) DEFAULT 'Draft'
ALTER ENUMERATION
Add, rename, re-caption, or remove values on an existing enumeration:
-- Add a new value (the CAPTION keyword is required for ALTER, unlike CREATE)
ALTER ENUMERATION Sales.OrderStatus
ADD VALUE OnHold CAPTION 'On Hold';
-- Rename a value's identifier (the name used in code)
ALTER ENUMERATION Sales.OrderStatus
RENAME VALUE Draft TO Pending;
-- Change an existing value's display caption in place (the name is unchanged)
ALTER ENUMERATION Sales.OrderStatus
MODIFY VALUE OnHold CAPTION 'Temporarily On Hold';
-- Remove a value
ALTER ENUMERATION Sales.OrderStatus
DROP VALUE Draft;
MODIFY VALUE … CAPTION edits the caption without dropping the value, so it works
even while the enumeration is referenced by an entity attribute — unlike drop +
recreate, which is blocked by the reference. Several actions can be combined in one
statement (e.g. RENAME VALUE Draft TO Pending MODIFY VALUE Pending CAPTION 'Pending Review').
DROP ENUMERATION
Remove an enumeration entirely:
DROP ENUMERATION Sales.OrderStatus;
Dropping an enumeration that is still referenced by entity attributes will cause errors in Studio Pro.
See Also
- Primitive Types – all attribute types including enumeration references
- Data Types – type system overview
- Entities – using enumerations in entity definitions