This procedure provides instructions and an example on how to create a target path that returns an object instance from a collection property where a property of that object instance matches some value. The value to be compared against the collection must be accessible in the current context and therefore must be defined prior to performing this procedure. For this example, a detail screen field displaying a string will be used.
At run time the behavior of the Agentry Client will be to evaluate the target path and to compare the selected property in each instance the object in the collection property to the selected search value until a match is found. The first matching object instance is then returned. Note that this iterative processing can include up to as many iterations as their are object instances stored in the collection property. Typically this is not an issue for performance unless the collection contains an exceptionally large number of object instances (hundreds or thousands). However, if this target path is itself evaluated as a part of some outer loop of iterative processing, a performance issue could be encountered. For example, if the collection contains 100 object instances, and the outer loop iterates as little as 10 times, the total number of evaluations could be as many as 1,000.
Such a situation could also be encountered if the target path is evaluated in an update rule for a detail screen field. Update rules are evaluated numerous times during the initial presentation of the parent screen, and additionally whenever the user interacts with the detail screen. On a wizard screen, this would result in the target path being evaluated each time the user enters a character in a string field, or makes a selection in some list or drop down field on the same screen.
In this example the Property Browser is used to create a path that searches the OrderItems collection of an Order object for an OrderItem with a ProductID (key property) that matches the one currently selected in the AddOrderItem wizard. The goal is to display a clear indicator on the AddOrderItem wizard screen when a product is being selected that has already been added to the OrderItems collection. While the Agentry Client would prevent a second object with the same key property from being added to the collection, and an error message is displayed, this does not occur until the Agentry Client attempts to apply the transaction. A cleaner user interface is possible that displays a message as soon as the duplicate product is selected.
The label field contain the text DUPLICATE is to be modified with it’s Hidden Rule attribute set to a rule that checks the OrderItems collection for an object with a ProductID value equal to the one currently selected in the Product ID field of the AddOrderItem wizard. The rule will contain a target path that makes this check and returns the property ProductID from the object found. If no object is found, then a null value is returned by the target path. The return from this path is to be passed as a parameter to the rule function NOT, which treats any parameters as Boolean values and inverts them. The Hidden Rule evaluates the rule it contains in a Boolean context. When such a rule returns true, the field containing the attribute is hidden from the user. When it is false, the field is displayed.
The overall logic, then, will be that the user selects a product from the complex table. The Hidden Rule for the label field DuplicateFlag will be evaluated. This rule contains the target path that compares the selected ProductID value to the ProductID property of each object in the OrderItems collection. If a match is found, the ProductID value of that object is returned to the NOT function within the rule. This is treated by the NOT function as true, since the path is evaluated in a Boolean context and any non-null value is true. NOT inverts this value, thus returning false to the Hidden Rule attribute. This results in the DuplicateFlag field being displayed. On the wizard screen the text DUPLCIATE is displayed in large red text. If the user selects a product that is not currently found in the OrderItems collection, the target path in the Hidden Rule will not find a matching object. The value returned by the path will be NULL. The NOT function treats NULL as false. It will then invert this value, returning true to the Hidden Rule attribute. This will hide the DuplicateFlag field on the screen.
At this point, the changes made are complete. We will now publish and test this modification. the following examples are from the Agentry Test Environment.
When the user adds an OrderItem
for an Order, the AddOrderItem wizard is initially displayed:
When the user makes
a selection in the ID field, the Hidden Rule for the currently hidden
DuplicateFlag field, the target path built in the previous procedure
is evaluated within the rule definition. The value displayed in
the ID field is compared to the ProductID property in each OrderItem
object in the collection targeted by the AddOrderItem transaction.
If a match is found, the path returns the ProductID of that object
instance, which is treated as true. The NOT function inverts the
value within the rule, returning false. A false Hidden Rule value
indicates the field should not be hidden, and the field’s label
text is displayed:
The user has now
been informed that the product currently selected is already a part
of the Order. If the user then makes another selection, the Hidden
Rule, including the target path it contains, is evaluated again.
If no matching OrderItem is found, the DuplicateFlag field is hidden
and the user knows the product can be ordered: