Today I would like to briefly talk about whether we can skip/ignore field validation errors in Business Central.
Business Central validates data to improve its accuracy and reliability. When there’s an error, Business Central shows a small validation dialog to inform you.
For example, Item Tracking Code field in Item (27) table:
You cannot change Item Tracking Code because there are one or more ledger entries for this item.
And Bin Mandatory field in Location (14) table:
You cannot change Bin Mandatory because there are one or more open ledger entries on this location.
The logic of these processing is placed in OnValidate (Field) Trigger (Runs when user input is validated).
This trigger is run after the default validation behavior when data is entered in a field. During the default validation behavior, the system checks that the data type of the value entered matches the one defined for the field and that it complies with the property constraints set up in such field before the validation occurs. An error message displays if an error occurs in the trigger code. In case of an error, the user entry is not written to the database.
Item Tracking Code field in Item (27) table:
Bin Mandatory field in Location (14) table:
These are standard controls in OnValidate (Field) Trigger and shouldn’t be skipped or ignored, but more than once I’ve seen questions in the Dynamics 365 Business Central Forums about whether it’s possible to skip a particular field validation error. And as you might know, for the above Item and Location, the most correct approach should be to create new ones and then block the old records.
Let’s go back to the topic, so is there a way to skip it? Yes, there are generally two ways to do it, but I need to emphasize again that it is not recommended because it skips a lot of standard checks and processing.
1. Using Configuration Package (No customization)
When selecting table fields in the Configuration Package, we can disable Validate Field field.
Specifies whether the information in a field is to be validated during migration. Select the check box if you want to enable validation for the field. This is useful when you want to limit data to a prescribed set of options.
For example, in addition to the Item No. field, I only included the Item Tracking Code field and disabled Validate Field.
After importing from Excel:
No. of Fields Available: Specifies the count of the number of fields that are available in the migration table.
No. of Fields Included: Specifies the count of the number of fields that are included in the migration table.
No. of Fields to Validate: Specifies the number of fields to validate. The count of the number of fields to validate is based on how many fields in the table have the Validate Field check box selected.
In this case, no error occurs when executing Apply Package.
And, Item Tracking Code has been updated.
In short, this way skips the process in the OnValidate (Field) Trigger of the field.
More details about Configuration Package: How to Export and Import Data (Using Configuration Packages)
We can also make a simple customization to modify the field value without executing the process in OnValidate (Field) Trigger. This time we take Location (14) table as an example.
First, let’s look at what to do if we want to execute the OnValidate trigger.
Record.Validate(Any [, Any]) Method: Calls the OnValidate trigger for the field that you specify.
GeneralLedgerEntry.Validate("G/L Account No.", '100'); // This corresponds to: GeneralLedgerEntry."G/L AccountNo" := '100'; GeneralLedgerEntry.Validate("G/L Account No.");
So just use the assignment statement (“:=” operator) to skip OnValidate (Field) Trigger.
Very simple. Give it a try!!!😁
Hope this will help.
Thanks for reading.