Hi again,
I am trying to figure out how to prevent trying to add an already in use unique value to a collection when executing a command that updates the collection. The unique value of the collection is determined with a @default value. When executing the command with an unique value that already exists in the collection, it is, obviously, not added to the collection.
How can I prevent this? Is there a trick with adding @validate to the unique value? Besides, what does the function @validate: resolvable do?
Hi Martinique, in a command, you cannot use the @default: auto-increment, so you have to already know what the name of the new entry should be when you begin to create it. Most of the time, you can derive it from other unique names you already have. But another good approach is to add a command parameter which should contain the new, unique name. You can then default a value there with a guid, for instance.
There is a change coming in which you can say that a command parameter should contain a key that is not in a collection. It looks like a reference, but has the keyword new before the path to the collection. That would surely help as well.
@validate: nor @validate: resolvable cannot be used for this, it is used to validate a text with a regular expression. resolvable means that it is required that a link (~>) is pointing towards an actual entry.
You could set a separate stategroup command parameter with a
@expected: switch >'key that should be new' (
node => // no, it is not new..
none => // yes, we want that!
)
and then require the stategroup to be in the none state
1 Like