Data Validation: General Information
In MYOB Acumatica, you can perform data validation by using the FieldVerifying and RowUpdating event handlers.
Learning Objectives
In this chapter, you will learn how to do the following:
- Use the FieldVerifying event handler to independently validate the value of a field
- Throw the PXSetPropertyException exception to cancel the update of the field
- Invoke the RaiseExceptionHandling<>() method to display a warning to the user if the value of the field was corrected automatically after a failed validation
- Use the RowUpdating event handler to implement the validation for any number of fields based on the values of other fields of the same data record
- Use the Cancel property of the event arguments of the RowUpdating event handler to cancel the update process
Applicable Scenarios
You perform data validation in the following cases:
- You need to independently validate the data contained in a field of a data record before persisting it to the database
- You need to validate the data contained in any number of fields of a data record before persisting it to the database
Process of Data Validation
If you want to independently validate a value inserted by a user, you should implement the FieldVerifying event handler for the data field. You can use this approach to check restrictions on the absolute value. For details, see Data Validation: Validation of Field Values.
If validation depends on other fields of the same data record, you should implement the validation in the RowUpdating event handler. The RowUpdating event happens during the update of a data record, after all field-related events have occurred. At the moment when the RowUpdating event is triggered, the modifications have not been applied to the data record stored in the cache yet; if needed, you can cancel the update process.
For details, see Data Validation: Validation of a Data Record.