Major
Detail
Bugfix
Major
Detail
Major
#26444
Specification of the context object in TL-Script Object creation
Until now there is no possibility to pass the creation context to a default value function when the object is created in a TL Script operation.
With the customization "Default value" attributes of new instances can be assigned with a default value. The function for calculating a dyn. sequence name gets "the creation context" of the new instance to be created.
For the form-based creation of containment instances in composition relationships, this also seems to work.
But if the new instances are not created form-based, this creation context is not automatically defined:
For example, the command handler via expression on a table operates on the selected row as context, creates a composite instance and links it to the context. The function for calculating the dyn. sequence for the default value gets in this case the analage context "null".
On the other hand: A "Dialog for object creation" also gets the selected line as model, creates the new composite instance and links it in its link operation with the selected context. In this case, this creation context is also passed to the function for calculating the dyn. sequence for the default value. But if such an object creation creates the context object *and* the first composite instance *at the same time*, the component model of the creation dialog is irrelevant. Here the newly created context object would be the correct analage context and not the selected line.
If it were possible to pass the object just created as a parameter to the function for calculating the dyn. sequence name, and one could navigate from this instance to its container (composite parent), this problem would be solved. Such default values could then only be calculated *after* the link operation....
This also seems to be the perhaps better formulation: if the creation context of a composite instance does not result from the component model, but only from the link operation at creation, default values with dyn. sequence names do not work.
Solution
The TL script function new() receives an additional optional argument in which the attachment context can be specified. This creation context is also made available to any default value providers. If the installation is performed in a script, the context of the installation can be specified explicitly.
new(`my.module:MyType`, $myContext)
Test
- test.com.top_logic.model.search.expr.TestSearchExpression.testCreateWithContext()