v2.7 (latest)
GlobalCounter ​
Tenant-isolated named counters, shared across all rule executions within the same tenant.
Methods ​
get ​
javascript
get(name: string)Returns the current value of a named counter without incrementing it. Returns 0 if the counter has never been used.
Parameters
name string
The name of the counter.
Return type
number
Examples
javascript
GlobalCounter.get('invoice-number') // => 5 (current value)
GlobalCounter.get('new-counter') // => 0 (never used)next ​
javascript
next(name: string)Atomically increments a named counter and returns the new value. The counter starts at 1 on first use.
Parameters
name string
The name of the counter.
Return type
number
Examples
javascript
GlobalCounter.next('invoice-number') // => 1 (first call)
GlobalCounter.next('invoice-number') // => 2 (next call)set ​
javascript
set(name: string, value: number)Sets a named counter to a specific value. Useful for initializing a counter to a known starting value.
Parameters
name string
The name of the counter.
value number
The value to set the counter to.
Return type
number
Examples
javascript
GlobalCounter.set('invoice-number', 100) // => 100 (counter is now 100)
GlobalCounter.set('new-counter', 0) // => 0 (reset to zero)