C - Expert 3 - Calculations within collections
Table of contents
Purpose of the section is to introduce calculation within collections.
When we are comparing a value of an element to a number of occurrences of another element, we first have to find a shared context for both of these elements and keep in mind that we most likely are comparing a string value to an integer value, depending on the type defined in the schema.
In this rule, we can start by making a rule from scratch. We should select NumberOfTransactions from the tree, but this time choosing plus icon instead of a dropdown. Following empty modal should now be visible.
We now have to fill every mandatory text box manually.
First common type of the relevant elements has to be "Message", and OCL code will be as follows:
self.Header.NumberOfTransactions = self.Transaction->size()
->size() will return an integer of the amount of Transaction elements.