Skip to main content

Notifications

Announcements

No record found.

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 350

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
    Olister Rumao 3,957 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

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