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...
Answered

Limiting a list view lookup to filter on two different columns using OR

(0) ShareShare
ReportReport
Posted on by 5

Hi All

I am trying to limit the records displayed in a List Page to the records which have ether Column A = X OR Column B = X. 

I have been trying the advice on Record.FilterGroup([Integer]) Method - Business Central | Microsoft Learn (Example 2) but I keep getting all the records as opposed to the limited view.

This is the code I have on the List page:

var
        ClientFilter: Code[20];

    procedure SetClientFilter(Client: Code[20])
    begin
        ClientFilter := Client;
    end;


    trigger OnOpenPage()
    begin
        if ClientFilter <> '' then begin
            rec.FilterGroup := -1;
            rec.SetFilter(Rec.Buyer,ClientFilter);
            rec.SetFilter(Rec.Seller,ClientFilter);
            rec.FindSet();
        end;
    end;
Any help would be appreciated.
Regards
Tony
  • Suggested answer
    Tony Simpson Profile Picture
    5 on at
    RE: Limiting a list view lookup to filter on two different columns using OR

    Thanks, works like a charm.

  • Verified answer
    Govinda Kumar Profile Picture
    2,211 Moderator on at
    RE: Limiting a list view lookup to filter on two different columns using OR

    Hi,

    According to Zhu's blog, "Record.FilterGroup(-1) cannot be used to add default filters in the OnOpenPage trigger."

    One possible solution is to create a separate buffer and apply FilterGroup(-1) on it. Set your (Rec) to that buffer. Alternatively, you can use Or conditions to select the filtered record..

    So you may consider using an alternate custom page and inserting the records on that page based on the filtered record in your buffer.. as Mr Zhu mentioned in his blog..

    Regards

  • Verified answer
    YUN ZHU Profile Picture
    82,671 Super User 2025 Season 1 on at
    RE: Limiting a list view lookup to filter on two different columns using OR

    Hi, hope the following helps.

    https://yzhums.com/28943/

    Thanks.

    ZHU

  • Tony Simpson Profile Picture
    5 on at
    RE: Limiting a list view lookup to filter on two different columns using OR

    Hi Govinda

    Thanks for your answer. Filtering on one column is not the problem it is filtering on two columns with an a logical "Or". In other words, show all rows where column rec.Buyer = ClientFilter OR rec.Seller = ClientFilter.

    Regards

    Tony

  • Govinda Kumar Profile Picture
    2,211 Moderator on at
    RE: Limiting a list view lookup to filter on two different columns using OR

    Try adding CurrPage.Update(); and remove the FindSet();

     If you are using FilterGroup, then filter on a different buffer and use 'if' in findset and update your page inside it

    hopefully it gives you some idea

  • Suggested answer
    Govinda Kumar Profile Picture
    2,211 Moderator on at
    RE: Limiting a list view lookup to filter on two different columns using OR

    Hi sir,

    It seems that when you execute the code, the filtered record is selected, but all other records are still visible. Are you trying to hide all the other records and only display the filtered record?

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 372 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 242

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 231 Most Valuable Professional

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans