Dynamics 365 Business Central: How to quickly get field length from table number and field number

Dynamics 365 Business Central

Hi, Readers.
Today I would like to share another mini tip about Business Central, how to quickly get field length from table number and field number in AL.
As you know, when creating a table field of Text data type or Code data type in BC, you need to define the length. For example, table 18 Customer:

When you assign a value from code, it cannot exceed this length. And we cannot extend the length of standard fields. So sometimes we need to get the length of the field for comparison. Is there any simple way to do this? Yes, in this post I mainly share two ways.
Test Field: Customer (18) -> Name (2, Text[100]) – table number (18), field number (2), field length (100)

1. Using codeunit 10 “Type Helper” -> procedure GetFieldLength:

For example,

2. Using FieldRef.Length() Method: Gets the maximum size of the field (the size specified in the DataLength property of the field).

These two methods are usually used for finding the defined length of code and text fields. Give it a try!!!😁

PS:
1. Dynamics 365 Business Central: How to get fields in the keys of the table (Using KeyRef Data Type)

2. Dynamics 365 Business Central: How to get the id, type, length and value of a field by its text name (field name)

3. Dynamics 365 Business Central: How to export all keys in all tables

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL