FieldExist() and Field() get a text overload
FieldExist() and RecordRef.Field() in AL now have overloads that take a field name as text instead of only an integer field ID. The video explains the main use case: reading fields that third-party apps add to a table such as Customer through table extensions, without looking up IDs through page inspection. The demo reads the Customer No. field both by ID and by name from two customer list actions.
- Introduction to Business Central Musings
- Overview of FieldExist and Field overloads
- Use case - accessing table extension fields
- Traditional approach with field IDs
- New text overload functions in latest compiler
- Demo setup and code examples
- Demo execution with field ID and field name
- Summary and call to action
Overview
The video explains that Microsoft added overloaded versions of the existing FieldExist and Field functions. Before, a developer had to know the numeric field ID to check for or read a field on a RecordRef. This was awkward for fields that come from a table extension and are not in the base application.
The demo uses table Customer and two codeunit procedures, one that gets a value via field ID and one via field name. It shows FieldExist called with a field name, and Field called with a field name returning a FieldRef, to which the Value function can be chained. The video ties the overloads to the latest compiler release.
Key points
- FieldExist() now has an overload that accepts a field name as text, in addition to the integer field ID.
- Field() on RecordRef now has a text overload that takes a field name and returns a FieldRef.
- You can chain the Value function onto the FieldRef that Field() returns, so no FieldRef variable is needed.
- Main use case: reading fields that table extensions add (for example, from ISV apps such as Binary Stream or Insight Works) without knowing their field IDs.
- With the old approach, you find the field ID with page inspection, call FieldExist(id), then call Field(id).Value.
- The video calls these overloads, not new functions, that come with the latest AL compiler release.
- The demo adds two actions to the customer list (get field by ID, get field by name) that read the No. field value through a codeunit.
Features
Every feature below: status not stated, demoed.
AL objects mentioned
As heard in the captions. A name that matches one object page by exact type and name links to it; the others stay as named.
- table 18 “Customer” at 1:27
- codeunit “get value via field ID / get value via field name” at 8:25
Not found in BC28-30: codeunit “get value via field ID / get value via field name”.
Quotes
- 0:47 “related to two new functions that will appear in the latest AL compiler.”
- 0:59 “in fact existing functions but microsoft created overloaded versions of these functions”
- 2:47 “how can we get the value of a field that’s not in the base application, but it’s a field that belongs to a table”
- 5:43 “open up the page inspection in uh in the client and try to locate that binary stream or insight works”
- 6:25 “with the latest release though we have uh an overloaded version of the field exist function and field exist as you can see here”
Presenters (as heard): Business Central Musings host.
