Skip to main content

Notifications

Announcements

No record found.

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

filter on multiple fields in a statement

Posted on by 115

Hello,

can someone explain me how to combine filters across multiple fields?

How do I filter for the following records in a query?
record 1: field A: value C, field B: value D
record 1: field A: value E, field B: value F
...

When I use SetFilter("Field A"; 'C | E') and SetFilter("Field B"; 'D | F'). I also get the record where field A has value E and field B has value D.

Thank you and best regards
Nico

  • GER_Nico Profile Picture
    GER_Nico 115 on at
    RE: filter on multiple fields in a statement

    Using the two methods, I retrieve each record individually. Unfortunately that doesn't solve my problem.

    I am working in a report with a dataitem. I can't pass many individual records there, just a filtered list.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 21,091 Super User 2024 Season 1 on at
    RE: filter on multiple fields in a statement

    Hi,

    You can try two method below

    Try with

    Record.Get("Primary Key first field","Primary Key second field");

    or 

    Record.reset;

    Record.setrange("Primary Key first field",<Value>)

    Record.setrange("Primary Key SEcond field",<Value>)

    Record.findfirst;

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-get-find-and-next-methods

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/fieldref/fieldref-setrange-method

    Thanks.

  • GER_Nico Profile Picture
    GER_Nico 115 on at
    RE: filter on multiple fields in a statement

    Sorry, I didn't explain my problem properly.

    I have a table whose primary key consists of two fields. This means that I can only uniquely select a record with a combination of the two fields. But I want to select multiple records at the same time, which means I have to specify multiple of these combinations as well.

    In my case it is about the "Job Task" table, which primary key is clustered by the fields "Job No." and "Job Task No.". I would now like to select job task 1000 from job 12345 and job task 1200 from job ABCD. But I don't know how to specify the filter in order to only get these two job tasks and not also the job task 1200 from job 12345 and the job task 1000 from job ABCD.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,647 Super User 2024 Season 2 on at
    RE: filter on multiple fields in a statement

    Hi, hope the following helps.

    Cross-column search (OR filters on multiple fields) ★FilterGroup(-1)

    https://yzhums.com/28943/

    Thanks.

    ZHU

  • Suggested answer
    Inge M. Bruvik Profile Picture
    Inge M. Bruvik 32,748 Super User 2024 Season 1 on at
    RE: filter on multiple fields in a statement

    What your are using is an "or" filter so to me it looks like the system is behaving exactly as designed.

    What is the result you want to achieve with your filtering?

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans