Counter expression – drawing the next number¶
The counter expression draws the next number from a counter, for example for ticket or invoice numbers. How counters are set up – start value, increment, automatic reset, scopes – is described on the page Counters.
1. At a glance¶
| Purpose | Increments a counter and returns the new value |
| Typical use | Consecutive numbers such as INC-2026-00042 (together with a text expression and the rule PadLeft) |
| Returns | Whole number |
| Related | Counters |
2. Settings¶
| Setting | Meaning | Default |
|---|---|---|
| "Counter" | The counter that is used | – (required) |
| "Scope" | Only for counters with scopes: an expression for the scope key, for example the year or the customer number. Every key has its own running number. | – |
| "View Only" | Returns the current value without incrementing the counter | off |
3. Behaviour¶
- Every evaluation draws a new number. The counter is incremented in the database in a way that gives every evaluation a unique number, also when many users save at the same time.
- Before incrementing, an automatic reset configured on the counter is applied if it is due. The first number after a reset is the reset value.
- With "View Only", the current value is returned and the counter is not changed.
- In the preview of an editor, the current value is shown without incrementing.
- For a counter with scopes, an empty scope key makes the result empty – no number is drawn.
- The fields the "Scope" expression reads count as fields the counter expression reads. In a calculation rule with "Trigger on any change", changing such a field runs the rule again and draws a new number.
Because every evaluation consumes a number, use the counter expression only where it is evaluated exactly once on purpose – typically in an action command or a business rule that writes the number into a field when a record is created. In a caption, a grid column or a form display it would draw a new number every time it is shown, and the numbers would have gaps.
4. Example¶
Ticket number on creation: A default value rule of the entity "Ticket" writes the text expression
INC- + a Modify Value expression into the field "Number". The modify value
expression takes a counter expression ("Ticket counter") as input and applies the rule PadLeft
with the parameters 0 and 5. Result: INC-00042.