ID generation
Syntax
nextId($sequence)
Description
Creates a new unique number in the sequence with the given name. The return value is an integer. Multiple calls with the same sequence name will generate different sequential numbers. Calls with different sequence names can generate the same number.
Multiple arguments can be passed. In this case, all arguments are concatenated into one sequence name. If an argument is not a string, it is converted to a string. If an argument is a business object, its internal technical ID is used to serve as the sequence name. This can be used to generate a sequence of sequential numbers for a given compartment object.
The function may only be called in a transaction context.
Parameters
Name | Type | Description | Mandatory | Default |
---|---|---|---|---|
sequence | String | Name of the sequence. Can also be specified in several parameters that are concatinated. | yes |
Return value
Type: Number
An integer from the named sequence.
Examples
A sequence
{
a = new(`my.module:MyClass`);
$a.set(`my.module:MyClass#name`, "A" + nextId("Seq1"));
b = new(`my.module:MyClass`);
$b.set(`my.module:MyClass#name`, "B" + nextId("Seq1"));
list($a, $b);
}
Output: A list of objects with the following names: [A1, B2]
Multiple sequences
{
a = new(`my.module:MyClass`);
$a.set(`my.module:MyClass#name`, "A" + nextId("Seq1"));
b = new(`my.module:MyClass`);
$b.set(`my.module:MyClass#name`, "B" + nextId("Seq1"));
c = new(`my.module:MyClass`);
$c.set(`my.module:MyClass#name`, "C" + nextId("Seq2"));
list($a, $b, $c);
}
Output: A list of objects with the following names: [A1, B2, C1]
Here, the object c
is assigned the number 1
, because the ID was generated with a different sequence than a
and b
.