How to show the SQL statement of a query ?

You must just write this line for show the SQL code generate by the query :


All SQL code about the query in save in the FIRST datasource.

Print a report to PDF into a folder

From this Source

My personal code for generate a PDF from a standard report (SalesInvoice, …)

private void generatePDF()
    ReportRun           report;
    RecordSortedList    list        = new RecordSortedList(tableNum(MyTable));
    FileName            fileName    = "C:/test.pdf";
    PrintJobSettings    settings;


    report = new ReportRun(new Args(ReportStr(MyReport)));


    settings    = report.printJobSettings();

Research : replace findRecords

Calling research() will rerun the existing form query against the database, therefore updating the list with new/removed records as well as updating all existing rows. This will honor any existing filters and sorting on the form, that were set by the user.


The research method starting with AX 2009 accepts an optional boolean argument _retainPosition. If you call research(true), the cursor position in the grid will be preserved after the data has been refreshed. This is an extremely useful addition, which solves most of the problems with cursor positioning (findRecord method is the alternative, but this method is very slow).

Make an OR in a query

Simple select query in Ax Client:

static void projTableJob(Args _args)
    ProjTable   projTable;
    while Select projTable where projTable.ProjId Like "305492-00*" ||
                                 projTable.Name   Like "305492-00*"
        print projTable.Name;

Using Query Classes in Ax Client: The same query is implemented by using Query classes in Ax client

static void projTableJobUsingQuery(Args _args)
    Query                   query;
    QueryBuildDataSource    qb, qb1;
    QueryBuildRange         qbr, qbr1;
    QueryRun                qr;
    ProjTable               projTable;
    str                     myvalue = '305492-00*';
    query = new Query();
    qb = query.addDataSource(tablenum(ProjTable), "ProjTable");
    qbr = qb.addRange(fieldnum(ProjTable, ProjId));
// Here the OR condition is implemented.   
    qbr.value(strfmt('(%1.%2 Like "%3") || (%1.%4 Like "%5")',
                fieldstr(ProjTable, ProjId), any2str(myvalue),
                fieldstr(ProjTable, Name),  any2str(myvalue)
    qr = new QueryRun(query);
    while (
        projTable = qr.get(tablenum(ProjTable));
        print projtable.Name;