Use variables in flowfield calcformula

Ale
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
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
Best Answers
-
Hello!
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 25 -
It's the way to go about this sort of problems, however the Description field becomes static and won't be updated if Customer, or Vendor or Item name changes, unlike in a 'normal' flowfield case.
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.Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035
Answers
-
Hello!
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 25 -
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 this0 -
It's the way to go about this sort of problems, however the Description field becomes static and won't be updated if Customer, or Vendor or Item name changes, unlike in a 'normal' flowfield case.
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.Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions