Skip to main content

Notifications

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

 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

  • Sachin Mittal Profile Picture
    on at
    RE: how use OR Condition on multiple query Ranges in D365 F&O

    Thankyou so much for helping !!

  • Suggested answer
    Mohit Rampal Profile Picture
    12,558 Moderator on at
    RE: how use OR Condition on multiple query Ranges in D365 F&O

    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
    on at
    RE: how use OR Condition on multiple query Ranges in D365 F&O

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

    this range is not working

  • Mohit Rampal Profile Picture
    12,558 Moderator on at
    RE: how use OR Condition on multiple query Ranges in D365 F&O

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

  • Sachin Mittal Profile Picture
    on at
    RE: how use OR Condition on multiple query Ranges in D365 F&O

    its not returning expected output

  • Suggested answer
    Mohit Rampal Profile Picture
    12,558 Moderator on at
    RE: how use OR Condition on multiple query Ranges in D365 F&O

    Hi Sachin, Please check this article

    www.linkedin.com/.../

  • Suggested answer
    Anton Venter Profile Picture
    19,595 Super User 2025 Season 1 on at
    RE: how use OR Condition on multiple query Ranges in D365 F&O

    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
    André Arnaud de Calavon Profile Picture
    294,110 Super User 2025 Season 1 on at
    RE: how use OR Condition on multiple query Ranges in D365 F&O

    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   ')';

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

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans