Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

It is possible to use a variable in the TableRelation filter inside a field?

Posted on by 42

I would like to use a variable in the TableRelation filter instead of 'INDUSTRY'. 

This is the code:

 field(50517; "Industry"; Code[20])
        {
            DataClassification = ToBeClassified;
            Caption = 'Industry';

            TableRelation = "Dimension Value".Code where("Dimension Code" = filter(= 'INDUSTRY'));
Thanks in advance, 

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,698 Super User 2024 Season 2 on at
    RE: It is possible to use a variable in the TableRelation filter inside a field?

    Hi, I think you can refer to the practice in the standard Sales Line.

    pastedimage1681881427580v1.png

    pastedimage1681881465689v2.png

    Hope this helps as well.

    Thanks.

    ZHU

  • Verified answer
    Gianfranco C. Profile Picture
    Gianfranco C. 370 on at
    RE: It is possible to use a variable in the TableRelation filter inside a field?

    I think I understand what you mean:
    you want to use a global variable in the table relation filter.
    but unfortunately this is not possible, according to the documentation:

    TableRelation Property - Business Central | Microsoft Learn


    as an alternative to the table relation you can set the OnLookup trigger like this:

    field(50517; "Industry"; Code[20])
            {
                DataClassification = ToBeClassified;
                Caption = 'Industry';
                trigger OnLookup()
                var
                    DimensionValue: Record "Dimension Value";
                    DimensionValuesPage: Page "Dimension Value List";
                    MyVariable: Code[20];
                begin
                    MyVariable := 'INDUSTRY';
                    DimensionValue.SetRange("Dimension Code", MyVariable);
                    if DimensionValue.FindSet() then begin
                        DimensionValuesPage.LOOKUPMODE := true;
                        DimensionValuesPage.SetTableView(DimensionValue);
                        if DimensionValuesPage.RunModal() = ACTION::LookupOK then begin
                            DimensionValuesPage.GetRecord(DimensionValue);
                           "Industry" := DimensionValue.Code;
                        end;
                    end;
                end;
            }

    Don't forget to help the community by Verifying the answer and Like it if your question has been answered. It will let others know that the topic has verified answer.

    Thanks & Regards,
    Gian

  • Suggested answer
    Govinda Kumar Profile Picture
    Govinda Kumar 2,203 Super User 2024 Season 1 on at
    RE: It is possible to use a variable in the TableRelation filter inside a field?

    you can use the global variable in table relation you can use the table field as Mohana said,

    TableRelation="Dimension Value".Code where("Dimension Code" = field(YourFiled));

    regards

  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,139 Super User 2024 Season 2 on at
    RE: It is possible to use a variable in the TableRelation filter inside a field?

    I dont think we can use variable there but you can use a field.

    TableRelation = "Dimension Value".Code where("Dimension Code" = field("field name"));

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans