Web Shell Event Handler: Retrieve Default Data When a Field Changes

Similar to the ValidateFieldHandlers property, the FieldChangedHandlers property allows you to add a FieldEventHandler for a particular field within the batch grid user interface. When the assigned field changes, the AddressOf operator designates a delegate to handle the event. The code below adds a FieldChangedHandler to the batch. When the food item ID drop-down value changes within the transaction detail child grid, the GetFoodItemDetails delegate retrieves default data using the DataFormLoad function.

GetFoodItemDetails programmatically calls upon a data form as a mechanism to retrieve data from the database and into the batch handler. DataFormLoad is called to retrieve data from a feature represented by DATAFORMID_FOODITEMINFO. The record to retrieve is identified by the ID variable. After the data is retrieved, the DataFormItem object, which represents the data payload retrieved from the database, is used within a call to TrySetValuesFromDFI, which sets the matching form fields from the DataFormItem to the batch row. The batch row is represented by e.Model.

Also note the use of the CreateChangeSuppressor, which is used when you do not want other event handlers or "listeners" to respond to changes that your code makes. While this suppressor object is alive, field changes are ignored on the model specified. When the object suppressor is disposed of, all the fields that were changed during its lifetime are validated, but no field changed events are fired.

Figure: When the FOODITEMID value changes, GetFoodItemDetails is called to retrieve default data via a call to a data form.

Figure: When a food item is selected within the batch grid...

Figure: ...the field changed handler will fire and the default amount and quantity will be provided.