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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

how use OR Condition on multiple query Ranges in D365 F&O

(0) ShareShare
ReportReport
Posted on by 4

 query buildQuery()
    {
        
            QueryBuildDataSource	qbdsDistributorWorkerTarget,qbdsOAE1PSRHierarchy;
            Query query				= new Query(queryStr(OABCustomerReportLookupDetail));
            qbdsDistributorWorkerTarget =  query.dataSourceTable(tableNum(OAE1DistributorWorkerTarget));
            qbdsOAE1PSRHierarchy        =  query.dataSourceTable(tableNum(OAE1PSRHierarchy));
           
            qbdsDistributorWorkerTarget.addRange(fieldNum(OAE1DistributorWorkerTarget, ModifiedDateTime)).value(queryRange(fromDate,toDate));
   
            //Employee Code
            Employee = con2Str(EmployeeCon);

            if(Employee)
            {
                Employee = strReplace(Employee,';',',');
                qbdsOAE1PSRHierarchy.addRange(fieldNum(OAE1PSRHierarchy, ASM)).value(Employee) ;
                qbdsOAE1PSRHierarchy.addRange(fieldNum(OAE1PSRHierarchy, PSRSalesman)).value(Employee);
                qbdsOAE1PSRHierarchy.addRange(fieldNum(OAE1PSRHierarchy, OABSalesExecutivecode)).value(Employee);
                     
            }
        
            return query;
        }

I have added my query, now under if condition there are three ranges as of now I have passed, but I want if any of condition is true, query range work , now it works only  when all three ranges are simultaneously passed

I have the same question (0)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    304,750 Super User 2026 Season 1 on at

    Hi Sachin,

    You can use an or statement by using an advanced query expression on e.g. the RecId field. See next example:

    qbdsOAE1PSRHierarchy.addRange(fieldNum(OAE1PSRHierarchy, RecId)).value(
        '(OAE1PSRHierarchy.ASM == '   Employee  
        ' || OAE1PSRHierarchy.PSRSalesman == '   Employee   '
        ' || OAE1PSRHierarchy.OABSalesExecutivecode == '   Employee   ')';

  • Suggested answer
    Anton Venter Profile Picture
    20,670 Super User 2026 Season 1 on at

    To use an OR on different fields, you need to use "Expressions in query ranges", have a look at the link below. Also search for "Expressions in query ranges" for more information.

    learn.microsoft.com/.../using-expressions-in-query-ranges

  • Suggested answer
    Mohit Rampal Profile Picture
    12,573 Moderator on at

    Hi Sachin, Please check this article

    www.linkedin.com/.../

  • Sachin Mittal Profile Picture
    4 on at

    its not returning expected output

  • Mohit Rampal Profile Picture
    12,573 Moderator on at

    Please share your code that you wrote after going through above suggestions.

  • Sachin Mittal Profile Picture
    4 on at

     qbdsOAE1PSRHierarchy.addRange(fieldNum(OAE1PSRHierarchy, RecId)).value('(OAE1PSRHierarchy.ASM == '   Employee  ' || OAE1PSRHierarchy.PSRSalesman == '   Employee   ' || OAE1PSRHierarchy.OABSalesExecutivecode == '   Employee   ')');
                

    this range is not working

  • Suggested answer
    Mohit Rampal Profile Picture
    12,573 Moderator on at

    Can you try below code

    Employee = strReplace(Employee,';',',');
    
    qbdsOAE1PSRHierarchy.addRange(fieldNum(OAE1PSRHierarchy, ASM)).value(
        strFmt('((%1.%2 == "%5") || (%1.%3 == "%5")) || (%1.%4 == "%5"))',
        qbdsOAE1PSRHierarchy.name(),
        fieldStr(OAE1PSRHierarchy, ASM),
        fieldStr(OAE1PSRHierarchy, PSRSalesman),
        fieldStr(OAE1PSRHierarchy, OABSalesExecutivecode),
        Employee));

    Check this old thread

    community.dynamics.com/.../how-to-add-range-on-multiple-field-with-same-value

  • Sachin Mittal Profile Picture
    4 on at

    Thankyou so much for helping !!

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 621

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 575 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans