DefineFieldRules

Public Event DefineFieldRules(sender As Object, e As System.EventArgs)

The DefineFieldRules event is used to setup the business logic for field behavior. Since batch types support entering a variety of data, some fields may need to be required, validated, or disabled based on the row's context. In this event, these rules can be added to the BatchEntryHandler's FieldRules property. The FieldRules property has four major collections of rules that can be added.

Rules Collection Description

ValidInContextRules

When a field becomes not valid in context, then the field's value is cleared, the field is disabled, and the field is marked as not required. When a field becomes valid in context, then the field is enabled and populated with the default value.

EnabledRules

Defines the criteria used to determine if the field is enabled.

RequiredRules

Defines the criteria used to determine if the field is required input.

VisibleRules

Defines the criteria used to determine if the field is visible. 

Below is an example of a web batch event handler class that is used to define field rules for addresses. The first rule will evaluate the DONOTMAIL field within a row in the batch grid. If DONOTMAIL is selected, then the Do Not Mail Reason field becomes valid allowing the end user to provide a value for the reason. If unchecked, the field becomes invalid and the field is cleared, disabled, and marked as unrequired.

Invalidate fields in a batch with a ValidInContextRule

Rules from Multiple BatchEntryHandler Classes Are Combined

Since multiple BatchEntryHandler classes can be used with a single Batch Type,  and since each individual BatchEntryHandler can define its own rules, the batch framework will combine rules for matching fields using a logical AND operation. So in the following scenario:

SUB BatchEntryHandlerA _DefineFieldRules()
	Me.FieldRules.EnabledRules.add(“FIELD1”, FieldValue(“FavoriteColor”)=”Red”)
END SUB
 
SUB BatchEntryHandlerB _DefineFieldRules()
	Me.FieldRules.EnabledRules.add(“FIELD1”, FieldValue(“Sign”)=”Leo”)
END SUB

In this scenario, two different handlers specified rules for the same field, "FIELD1." The framework will combine these two rules into a single rule for "FIELD1": FieldValue("FavoriteColor")="Red" AND FieldValue("Sign")="Leo."