Validate and Invalidate Fields

Constituents who donate food to a food bank will be provided with a printed receipt for tax purposes. The Transaction Type field tracks the type of food donation. A transaction type of "Receive" designates that the food bank received food from the constituent. When this occurs, we want to enable and allow the Receipt Printed checkbox to be checked. When the transaction type is equal to "Distribute," then we do not want the Receipt Printed field to be available for editing.

Fortunately, we can add a field rule to the FieldRules.ValidInContextRules collection that determines if the field is valid in the given context by associating the Receipt Printed field within the batch with a deferred condition object. 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.

Add a field rule to the FieldRules.ValidInContextRules collection

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.

When the Transaction Type is set to Distribute, the Receipt Printed field will be cleared and disabled.