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
0
Answers
In this case you cannot use 'if' in flowfield.
You can use some code for update Description filed in OnValidate trigger field 1 and field 2
{
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
If you need the Description to be updated you'd have to create a code, 3 separate functions subscribing to OnAfterModify in Customer, Vendor and Item and keep your Description field updated when the name changes in any of these.
As an alternative (albeit also far from perfect) you could create 3 'regular' flow fields, one for Customer, one for Vendor and one for Item respectively and control their visibility on pages.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03