Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

TableRelation conditionnal doesn't work

(0) ShareShare
ReportReport
Posted on by 215

Hello,

On table 263 - Intrastat Jnl. Line, I added a field in the TableExt : 

        field(8008001; LineType; Option)
        {
            Caption = 'Lige Type';
            DataClassification = ToBeClassified;
            OptionCaption = 'Item, Resource';
            OptionMembers = Item, Resource;
        }
And I've modified the field 20 - 'Item No.' :
        modify("Item No.")
        {
            TableRelation =
            if (LineType = const(Item)) Item
            else
            if (LineType = const(Resource)) Resource;
         }
My prupose is : when a user on the page 311 Intrastat Journal adds a new entry, depending on if he choses Item or Resource in the field "Line type", the lookup they will see when they click on the field "Item No." will show items or resources.
The problem is : it doesn't work with this code. When I choose the option Resource, I only see items in the "Item No." Lookup on page 311.
What can I do to make it work please ?
  • Magicrevette Profile Picture
    215 on at
    RE: TableRelation conditionnal doesn't work

    I created a new field in the TableExt of Table 311 with the code of the standard field in it, plus my conditional TableRelation instead of the standard "TableRelation = Item". I also created a new field in the pageExt of Intrastat Journal to displays this new table field. And now it works !

    Here is the code of my new tableExt field and pageExt field : 

    TableExt "Intrastat Jnl. Line" :

            field(1500; PWS_ItemNo; Code[20])
            {
                Caption = 'Item No.';
                TableRelation =
            if (LineType = const(Item)) Item
                else
                if (LineType = const(Resource)) Resource;

                trigger OnValidate()
                var
                    Item: record Item;
                begin
                    TestField("Source Type", 0);

                    if "Item No." = '' then
                        Clear(Item)
                    else
                        Item.Get("Item No.");

                    Name := Item.Description;
                    "Tariff No." := Item."Tariff No.";
                    "Country/Region of Origin Code" := Item."Country/Region of Origin Code";
                    GetItemDescription;
                end;
            }
    pageExt  "Intrastat Journal" : 
            addafter("Item No.")
            {
                field(PWS_ItemNo; PWS_ItemNo)
                {
                    visible = true;
                    ApplicationArea = All;
                    Caption = 'PWS Item No.';
                    ToolTip = 'PWS Item No.';
                }
            }

    The former field (still doesn't work) : 

    pastedimage1600070759785v1.png

    The new field (it works) : 

    pastedimage1600070789550v2.png

    I think the problem comes from the property "TableRelation = Item" in the standard Table field "Item No.". In MS doc, it seems to say that the original TableRelation property cannot be changed. https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-tablerelation-property

  • Suggested answer
    THE Italian Profile Picture
    on at
    RE: TableRelation conditionnal doesn't work

    Looks good to me. What if you create the same Item No. like e.g. extItemNo. with the same code in the standard and extend this? Just to double check if this is related to standard field or custom table extension field extended a second time through your extension. 

    Last check. What is the build no. you are testing with? 

  • Magicrevette Profile Picture
    215 on at
    RE: TableRelation conditionnal doesn't work

    Reflex from NAV 2018. I'v changed the field Option to Enum (I created an Enum).

    The result is the same :/ 

            
            enum 8007852 PWS_IntrastatJnlLine
            {
                Extensible = true;
                value(0; Item{ }
                value(1; Resource{ }
            }
            field(8008001; LineType; Enum PWS_IntrastatJnlLine)
            {
                Caption = 'Type Ligne';
                DataClassification = ToBeClassified;
            }
            modify("Item No.")
            {
                TableRelation =
                if (LineType = const(Item)) Item
                else
                if (LineType = const(Resource)) Resource;
             }
    pastedimage1599831487032v2.png
    Here, I only see Items in the Lookup, not Resources, even if the "Type ligne" shows Resource.
  • Suggested answer
    THE Italian Profile Picture
    on at
    RE: TableRelation conditionnal doesn't work

    Why you have added an Option and not an Enum?

    Check this out

    ammolhsaallvi.blog/.../

    I would have used an Enum instead of the option. Give it a spin

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
YUN ZHU Profile Picture

YUN ZHU 628 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 495

#3
Sagar Dangar, MCP Profile Picture

Sagar Dangar, MCP 395

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans