Tip checking class context in scripts
When managing an event in a script associated with a class, refer to the 'CURPTH' value to obtain the exact scope. For example:
* You can manage a sales order class called 'SALESORDER'.
* This class includes an array of LINES instances (class 'SORDERLINES').
* You have a script 'SALESORDER_CSTD' associated with the sales order header.
* You have a script 'SORDERLINES_CSTD' associated with the sales order lines.
In the previous example, if you consider only the 'SALESORDER_CSTD', the event 'AINSERT_CONTROL_BEFORE' is called in any of the following cases:
* If a new sales order is created.
* When a new line is added in the sales order during a creation transaction.
* When a new line is added in the sales order during an update transaction.
So, the creation of a new sales order is not the sole condition that triggers the 'AINSERT_CONTROL_BEFORE' event.
You can distinguish the case by considering the value of 'CURPTH':
- If 'CURPTH' is empty then we are at the same level, that is the header level, and we are inserting a new sales order.
- If 'CURPTH' is equal to "SORDERLINE" then we are at the line level and we are inserting a new line.
There is also an 'AINSERT_CONTROL_BEFORE' event called in the 'SORDERLINE_CSTD' script that handles the line insertion. Normally, this script should be dedicated to local controls that suggest only the current line, while the 'SALESORDER_CSTD' script will be used for more global controls or updates.