If Iris does propose to create keys following a sequence, how can we obtain a sequential number in another context?
In my case, I automatically create care centers, and I want to set them a number like:
APP-DD-999
APP = Name of the application used by the center
DD = center department number
999: sequential number in the department
It is of course possible that centers will be created in competition, so this possible competition must be managed.
My first approach was to use a persistent class and create a new object to retrieve its id, but this involves creating as many classes as departments.
The solution I found involves using a global and the $INCREMENT function. The $INCREMENT function manages concurrency so it's perfect for my use.
So here is my method for obtaining a sequence:
ClassMethod GetSequence(name As %String, item As %String) As %Integer
{
Return $INCREMENT(^Sequence(name,item))
}
ObjectScriptObjectScript
Successive calls to this method provide the expected result:
BNA2024 6d3>w ##class(Ellipse.Utils.PlSandbox).GetSequence("departement",83)
1
BNA2024 6d3>w ##class(Ellipse.Utils.PlSandbox).GetSequence("departement",83)
2
BNA2024 6d3>w ##class(Ellipse.Utils.PlSandbox).GetSequence("departement",83)
3
ObjectScriptObjectScript
Hi @Pierre LaFay
you can also use $SEQUENCE
$SEQUENCE is intended specifically for integer increment operations involving multiple simultaneous processes.
$sequence can leave "holes" in numbering which can be undesirable in some cases, e.g. when meaningful IDs are assigned: it seems to be strange to have APP-DD-99 and APP-DD-101 without APP-DD-100.
You're right @Alexey Maslov ; in @Pierre LaFay 's case, $INCREMENT is better as this avoids gaps in the numerical sequence.