One aspect where A12 modeling does not make much sense to me is the handling of repeatable groups regarding the count of group instances.
Please help us out with some background info here, even though the text below is a bit lengthy.
In the docs it says
The Repeatability property sets the maximum amount of instances that are allowed to be created for the group.
Nice and easy to understand - or so it seems.
First doubt
When I tried to add a validation “There must be at least one item in your order” (items is a repeatable group), I naturally expected a function in the validation language like NumberOfGroupInstances(<group>).
All I found is NumberOfFilledGroups which is documented as
NumberOfFilledGroups determines the number of specified groups in a group list.
So a group is now a group list and instances (?) are “specified groups”?
What does “Specified” even mean? Oh wait,
A group is considered specified if it contains a specified field or subgroup.
Huh? Kinda recursive, isn’t it? (Reminds me of the classic Hacker’s Dictionary: “recursion: See recursion. See also tail recursion”
)
Oh, after reading some more docs it seems that “specified” is just another name for “filled” (Why two different words for the same thing? Is someone actively trying to confuse me?)
So, oookay, NumberOfFilledGroups kind of works for me here, because there are mandatory fields in the item group.
(So that when there is in fact an order item, but it is “unfilled”, then even though the “at least one order item”-validation would (erroneously) trigger, at least some real validation errors on the mandatory fields would show up).
Still feels like an ugly workaround.
Second doubt
On the “Item” group I have a computation like [TotalPrice] <- [Amount] * [UnitPrice]
I had in mind that in 2022.06 you no longer need to specify a precondition in a computation rule, if there is only one calculation.
When I tried that, I got a most peculiar error message
If the calculated field is repeatable, every partial calculation has to have values for its respective iteration".
Sorry, but from (my limited) modeler’s perspective that is gibberish.
I found some documentation that says
If the computed field is repeatable, the computation is carried out for each single repetition. In this case, the preconditions must assure that there is already some field value specified for the respective repetition layer.
This implies in particular: If the computed field is repeatable, then preconditions must be specified.
Note that, without such a restriction, even for an initially empty document the value 0 would be mapped into all 99 instances of TotalAmount.
Remarks:
- The error message talks about how the “calculation has to have values”. Why is that any different in a non-repeatable group?
- Couldn’t you change the error message to “If the computed field is repeatable, then preconditions must be specified.” - at least that would give me a hint what I actually have to do to fix the error.
- WTH, srsly? Does that mean if I have a repeatability of 999, then the computation would check the preconditions 999 times even if there currently are only 2 instances of the group?
Yet another doubt
Do we maybe have this (to me) strange “Confirm” data type, just so that I can still use stuff like NumberOfFilledGroups?
With the more common Boolean data type, the group would be considered “filled” right?
The doc just says
A Confirm field is either true or not set (null).
but does not even mention why we would need a data type with these values (instead of the saner true/false)
Conclusion
It feels like some implementation decisions that were made long ago, have side effects that are leaking into the modelling experience.
Could somebody shed some light, please?