web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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 2

 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
    301,075 Super User 2025 Season 2 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,346 Super User 2025 Season 2 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,565 Moderator on at

    Hi Sachin, Please check this article

    www.linkedin.com/.../

  • Sachin Mittal Profile Picture
    2 on at

    its not returning expected output

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

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

  • Sachin Mittal Profile Picture
    2 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,565 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
    2 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 434 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans