AX / D365FO – How to test the Query syntax and results of a Query

Have you created an AOT Query and want to check if the syntax is correct and the results are what you expected?

You can create a Runnable class like show below

class TestQuery
{
    public static void main(Args _args)
    {
        /*
        Example job used to test query results with.:
        */

        QueryRun queryRun;
        Counter totalRecords;

        // Table Variables:

        VendTable vend;
        VendCertification VendCert;

        queryRun = new QueryRun(queryStr(...your Query name here..));

        if (queryRun.prompt()) //Here the query prompt will open, if you want you can change the filters
        {
            while (queryRun.next())
            {
                vend = queryRun.get(tableNum(VendTable));
                info(Vend.AccountNum);

                VendCert = queryRun.get(tableNum(VendCertification));
                info(VendCert.CertificationNumber);

                totalRecords++;
            }
        }

        info(strFmt("Total Records : %1", totalRecords));
    }
}

When you debug the code you can check the Query syntax by watching inside the queryRun variable

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s