Dynamics 365 Business Central: How to check whether a field is a Flowfield via AL (Check the class of the field)

Dynamics 365 Business Central

Hi, Readers.
Today I would like to share another mini tip about Business Central, how to check whether a field is a Flowfield via AL.

FlowFields display the result of the calculation described in the CalcFormula Property. For example, the Inventory field in the Item table shows the current inventory of the item and is calculated as the sum of the Quantity fields for all Item Ledger Entries in this item.

Source Code in Item table: FieldClass Property and CalcFormula Property

More details about FlowFields in Business Central: FlowFields (Sum, Average, Exist, Count, Min, Max, Lookup)

Recently I was asked an interesting question, is there any way to check if a field is a FlowField via AL. So in this post, I briefly introduce two ways.
Item (27) -> Inventory (68, Decimal)

1. Using FieldRef.Class() Method

FieldRef.Class() Method: Gets the value of the FieldClass Property of the field that is currently selected. This method returns an error if no field is selected.

FieldClass Property: Sets the class of the field.

ValueAvailable or changed withDescription
Normalruntime version 1.0A data entry field.
FlowFieldruntime version 1.0A calculated field.
FlowFilterruntime version 1.0To compute the results of FlowFields.

We can simply do the following example. (If condition is just for reference)

Source code:

pageextension 50110 ZYItemListExt extends "Item List"
{
    trigger OnOpenPage()
    var
        RecRef: RecordRef;
        FldRef: FieldRef;
        Msg: Label 'Field ''%1'' is a %2';
    begin
        RecRef.Open(Database::Item);
        FldRef := RecRef.Field(68);
        if FldRef.Class = FieldClass::FlowField then
            Message(Msg, FldRef.Caption, FldRef.Class);
    end;
}

2. Using Field Virtual Table (table 2000000041 “Field”)

The Field virtual table (ID 2000000041) contains information about fields in database tables. And it contains the Class field.

FieldDescription
TableNoThe ID number for the table.
No.The number assigned to the field.
Table NameThe name of the table.
FieldNameThe name of the field.
TypeThe data type assigned to the field, for example, decimal.
ClassThe class of the field, for example, FlowField.

We can do the same thing as above. (If condition is just for reference)

Source code:

pageextension 50110 ZYItemListExt extends "Item List"
{
    trigger OnOpenPage()
    var
        FieldRec: Record Field;
        Msg: Label 'Field ''%1'' is a %2';
    begin
        if FieldRec.Get(Database::Item, 68) then
            if FieldRec.Class = FieldRec.Class::FlowField then
                Message(Msg, FieldRec."Field Caption", FieldRec.Class);
    end;
}

Very simple, give it a try!!!😁

PS:
1. What happens if users don’t have permission to read the table set in a FlowField?

2. How to export all fields in all tables

End

Hope this will help.

Thanks for your reading.

ZHU

コメント

Copied title and URL