Skip to main content

Notifications

Community site session details

Community site session details

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

How do I filter records for lookup based on a selection of different field?

(0) ShareShare
ReportReport
Posted on by 358

I have got a Table called Category with the following field;

   field(50000; "Code"; Code[50])
        {
            DataClassification = CustomerContent;

        }
        field(50001; "Description"; Text[100])
        {
            DataClassification = CustomerContent;
        }
        field(50002; "Group"; Code[50])
        {
            DataClassification = CustomerContent;
            TableRelation = Group;

        }

and a Table called Group with the following fields;

   field(50000; "Code"; Code[50])
        {
            DataClassification = CustomerContent;

        }
        field(50001; "Description"; Text[100])
        {
            DataClassification = CustomerContent;
        }

I have list pages for those two tables I mentioned above for the user to enter data.

Note that every Category has a Group hence the TableRelation of Group as one of its fields in the table.

I have a Page that users get to select values of Group and Category;

page 50118 "Code Selection"
{
    PageType = StandardDialog;
    ApplicationArea = All;
    UsageCategory = Administration;

    layout
    {
        area(Content)
        {
            group(Select)
            {
                field(Group; Group)
                {
                    ApplicationArea = All;
                    TableRelation = Group;
                }
                field(Category; Category)
                {
                    ApplicationArea = All;
                    TableRelation = Category;
                }
            }
        }
    }

    actions
    {
        area(Processing)
        {

        }
    }

    var
        Group: Code[50];
        Category: Code[50];
        Rec_Item: Record Item;
        NoSeriesMgmt: Codeunit NoSeriesManagement;
        NoSeriesCode: Code[30];
        ItemNo: Code[30];
        Page_Item: Page "Item Card";

    trigger OnQueryClosePage(CloseAction: Action): Boolean
    begin
        NoSeriesCode := 'ITEM2';
        IF Confirm('Do you create new Item?') THEN BEGIN
            IF Group = '' then begin
                Error('Group cannot be empty.');
            end;
            IF Category = '' then begin
                Error('Category cannot be empty.');
            end;
            
            Clear(NoSeriesMgmt);
            Clear(Rec_Item);
            Clear(Page_Item);
            Rec_Item.Init();
            ItemNo := NoSeriesMgmt.GetNextNo3(NoSeriesCode, TODAY, true, false);
            ItemNo := UpperCase(Group)   '-'   UpperCase(Category)   '-'   ItemNo;
            Rec_Item."No." := ItemNo;
            Rec_Item.Category := Category;
            Rec_Item.Group := Group;
            Rec_Item.Insert(true);
            Page_Item.SetTableView(Rec_Item);
            Page_Item.SetRecord(Rec_Item);
            Page_Item.Run();
        END
        ELSE BEGIN
            Message('Item creation cancelled.');
        END;

    end;

}

I use this page to then do something with Item page's No. field.

However, what I am stuck at is, I want to filter the records of Category based on Group when the user is doing a lookup on Category.

Since the Category has Group attached to it, lets say record in Category looks like this;

Record 1) ABC[Code XXX[Group

Record 2) DEF[Code XXX[Group

Record 3) GHI[Code YYY[Group

Record 4) JKL[Code YYY[Group

Now in the Page I have created; if the user selections Group to be XXX, I want the Category table relation to show only records Record 1 and Record 2.

And if user selected Group to be YYY Category show only records Record 3 and Record 4.

Basically, filter the look up records of Category based on the value selected in Group.

I tried writing on Table Relation if(Group = const('XXX) Category where(Group = Filter('XXX))

and it did not work.

  • Suggested answer
    Olister Rumao Profile Picture
    3,959 on at
    RE: How do I filter records for lookup based on a selection of different field?

    Hi Mesam,

    Kindly refer this 

    www.archerpoint.com/.../dynamics-nav-how-program-lookups

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 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,017 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,852 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans