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 :
Dynamics 365 Community / Blogs / DAX Beginners / How to: Create Query with R...

How to: Create Query with Range through X ++

Christian Silva Profile Picture Christian Silva 707

Today I will be posting about how to create a simple query trough X++. I recommend creating  a simple query through code, specially for tests purpose, this code can be used with Dynamic Lookup which I will be posting about it next week.

I had a hard time trying to find how use range between dates so I hope to help not only who wants to create a query but also who wants to know how to use range with date.

// Create a new Job
static void CustDateRangeQuery(Args _args)
{
    Query                   query;
    QueryRun                queryRun;
    QueryBuildDataSource    qbds;
    QueryBuildRange         qbr;
    CustTable               custTable;
    ;

    // Instance the class Query
    query =  new Query();

    // Add DataSource to Query
    qbds = query.addDataSource( tableNum(CustTable));

    // Add a range
    qbr = qbds.addRange( fieldNum(CustTable,CreatedDateTime));

    // Set range value
    qbr.value(SysQuery::range( "01/01/2012","30/12/2012" ));

    // Run Query
    queryRun = new QueryRun(query);

    // Retrieves the next record from the query.
    while(queryRun.next())
    {
        // Get Result
        custTable = queryRun.get( tableNum(CustTable));

        // Show AccountNum
        info(custTable.AccountNum);
    }
}

Now, compile and check results.

Results



This was originally posted here.

Comments

*This post is locked for comments