Today I would like to briefly talk about the problem I saw in the Business Central forum yesterday morning, how to change field name/table name in the error message thrown by Record.TestField Method, more details: Setting BC Field to Mandatory.
During your work day, you might see notifications in Business Central that something went wrong, or that it wasn’t possible to post something, for example. There are many ways to handle error messages in Business Central, one of which is to use the Record.TestField Method.
- Record.TestField(Any) Method: Tests that the content of the field is not zero or blank (empty string).
- Record.TestField(Any, Code) Method: Tests whether the contents of a field match a given value.
- Record.TestField(Any, Any, ErrorInfo) Method: Tests whether the contents of a field match a given value.
Its advantage is that we do not need to customize the error message, but let the system automatically generate a simple and easy-to-understand error message.
Let’s look at a simple example:

Phone No. must have a value in Customer: No.=10000. It cannot be zero or empty.

Another example:

Phone No. must be equal to ‘777777’ in Customer: No.=10000. Current value is ‘123456’.

PS: If you don’t use the Record.TestField Method

Some customers need to change the names of standard fields or pages to meet their business needs, will this also be reflected in the error message for Record.TestField Method?
In conclusion, if you use TableExtension to modify the captions of tables and fields, it will also affect the Record.TestField Method. However, if you use PageExtension, it will not happen because this method takes the standard table and field captions. For example,
TableExtension:


PageExtension:


So please be aware that if you modify the captions of standard fields or tables, this may affect the display of standard error messages. Give it a try!!!😁
PS: If you’re a developer, when you call the TestField method, but don’t pass in the |ErrorInfo object, Business Central automatically generates the link to a page where a user can correct the issue. Business Central first gets the lookup or drill-down page for the record, and then finds the card page or lookup page and adds a navigation link to that card page. Business Central doesn’t add a link in the following situations:
- If the error is on the page that’s currently open.
- If the user doesn’t have permission to modify the underlying record.
More details: Business Central 2024 wave 1 (BC24): Go to pages that contain a field that’s causing a platform error
END
Hope this will help.
Thanks for reading.
ZHU




コメント