Use variables in flowfield calcformula

AleAle Member Posts: 7
Hello new here and new to AL.
I was wondering. I have 3 fields in a table:

field(1; Code; Code[20])
{
Caption = 'Code';
DataClassification = ToBeClassified;
TableRelation =
if ("Status Object" = const(Customer)) Customer
else
if ("Status Object" = const(Item)) Item
else
if ("Status Object" = const(Vendor)) Vendor;
}
field(2; "Status Object"; Enum "Status object")
{
Caption = 'Status Object';
DataClassification = ToBeClassified;
}
field(3; Description; Text[50])
{
Caption = 'Description';
DataClassification = ToBeClassified;
}


Now I want the field description to show me the name or description of the object ( vendor, item or customer ) that is in field 1 (code). I would normally do this with a flowfield and calcformula = lookup ... where ... but I can't implement an if statement here.

Thanks for the help

Best Answers

Answers

  • AleAle Member Posts: 7
    field(1; "Code"; Code[20])
    {
    Caption = 'Code';
    DataClassification = ToBeClassified;
    TableRelation =
    if ("Status Object" = const(Customer)) Customer
    else
    if ("Status Object" = const(Item)) Item
    else
    if ("Status Object" = const(Vendor)) Vendor;
    trigger OnValidate()
    var
    Customer: Record Customer;
    Item: Record Item;
    Vendor: Record Vendor;
    begin
    case "Status Object" of
    "Status Object"::Customer:
    begin
    Customer.Get("Code");
    Description := Customer.Name;
    end;
    "Status Object"::Vendor:
    begin
    Vendor.Get("Code");
    Description := Vendor.Name;
    end;
    "Status Object"::Item:
    begin
    Item.Get("Code");
    Description := Item.Description;
    end;
    end;
    end;
    }

    Did it like this
Sign In or Register to comment.