I recently have been asked how to access a single attribute of a list of objects. The use case was basically to script a derive profile property for "Requirements" and to show the IDs of all traced FTA events (those traced typically are created when deriving Requirements from fault tree events.
First idea was to use OCL which offers some nice feature that Java Script does not have. OCL allows to access an attribute on a list (or sequence) of objects. So the first attempt was:
self.mediniGetTracedElements(FTA::Event).id
Nice here: the function returns a sequence of objects but still with OCL I can use the . notation with an attribute. The language interprets that as "read the attribute id for each object in the sequence and replace the object by the value of the attribute".
Unfortunately the initial attempt failed. The reason here is that OCL is a typed language and "medinigetTracedElements" returns a list of objects - with no type information. So "id" is an unknown attribute. Java Script would be more relaxed here.
Anyway, the solution is to "cast" the list or more precisely to collect all objects into a typed sequence;
self.mediniGetTracedElements(FTA::Event)->selectByType(FTA::Event).id
That works as expected,
Happy OCL Scripting