How to use operator "or" in QueryBuildRange

This blog post is show how to apply OR conditions in query build ranges in a simple way on same field in a table. Let’s see the simple query :

select * from CustTable where AccountNum == '2001' || AccountNum == '2002'

We can find out solutions on MSDN by using expression in query ranges, but as it has lot of specifications which needs to be followed. However there is a simple way to do it :

static void Job12(Args _args)
    CustTable cust;
    Query query = new Query();
    QueryBuildDataSource qbds;
    QueryBuildRange queryRange1, queryRange2;

    qbds = query.addDataSource(tableNum(CustTable));

    queryRange1 = qbds.addRange(fieldNum(CustTable, AccountNum));

    queryRange2 = qbds.addRange(fieldNum(CustTable, AccountNum));


Result in string format as below image :

SELECT * FROM CustTable(CustTable_1) WHERE ((AccountNum = N'1168201') OR (AccountNum = N'9034518'))

Thanks for reading :). Happy New Year.

Max Nguyen

Max Nguyen
D365/AX, Azure Solution Architech - currently living and working in Seoul :)

Exception Handling in Dynamics 365 For Finance and Operation

When we write a code, or make a customization to Dynamics 365 For Operation which is using X++ should make use of Exception Handling to p...… Continue reading

Basic C# OOP Concept

Published on April 10, 2017