web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Create a table relation to a table with a composite primary key (5 fields)

(0) ShareShare
ReportReport
Posted on by 5

Hello everyone,

i'm struggeling to create a relationship in AL. Maybe someone can help with this or point me in the right direction.

I create a table (A). This table (A) should a have one to one relationship to another table (B). The other table (B) has a composite key based on 5 fields (Fields: V,W,X,Y,Z).

What steps a necessary to create this relationship?

field(1; "V"; Code[10])
        {
            Caption = 'V';
            TableRelation = B.V;
        }

Only one TableRelation on the first field seems not to work and i don't know how to setup the relation with all the other fields.

In the end, i want to select only one field on the page and i want to make sure, that it is the correct relationship.

I hope someone has an idea.

Greetings,

Ben

I have the same question (0)
  • Verified answer
    YUN ZHU Profile Picture
    99,084 Super User 2026 Season 1 on at

    Hi, hope the following helps.

    https://yzhums.com/22220/

    Thanks.

    ZHU

  • fluegelb Profile Picture
    5 on at

    Hello Zhu,

    thank you for your response.

    I just looked at it and i'm not sure if this solution fits for my case.
    Unfortunately it is not only about displaying a field accordingly, but to store the key (W,V,X,Y,Z) in table (A), so that I can later find the correct entry in table (B) in a code unit and use the fields of table (B) in my code.

    Maybe i misunderstood your solution, could you please explain how to apply your solution to my case?

    Greetings,

    Ben

  • fluegelb Profile Picture
    5 on at

    Hey Zhu,

    i found a fitting solution with your link under point "2. Using OnLookup (Field) Trigger and Page.RunModal() Method".

    The solution looks like this.

     field(2; V; Code[20])
    {
        Caption = 'V';
        trigger OnLookup()
        var
            "Table B-Record": Record "Table B";
        begin
             "Table B-Record".Reset();
            if Page.RunModal(Page::"Table B List Page", "Table B-Record") = Action::LookupOK then begin
                V := "Table B-Record".V;
                W := "Table B-Record".W;
                X := "Table B-Record".X;
                Y := "Table B-Record".Y;
                Z := "Table B-Record".Z;
            end;
        end;
    }


    Can you confirm that this solution is viable?

    Btw. you can ignore my other post.

    Greetings,

    Ben

  • Verified answer
    YUN ZHU Profile Picture
    99,084 Super User 2026 Season 1 on at

    Looks ok, great.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,946 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,177 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 555 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans