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;
    ;

    list.ins(myTable);

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

    report.args().caller(null);
    report.args().object(List);

    settings    = report.printJobSettings();
    settings.format(PrintFormat::PDF_EMBED_FONTS);
    settings.setTarget(PrintMedium::File);
    settings.viewerType(ReportOutputUserType::PDFEmbedFonts);
    settings.fileName(fileName);
    settings.lockDestinationProperties(true);

    report.run();
}

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.

research(true)

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;
    }
 
    pause;
}

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")',
                qb.name(),
                fieldstr(ProjTable, ProjId), any2str(myvalue),
                fieldstr(ProjTable, Name),  any2str(myvalue)
                ));
 
 
    qr = new QueryRun(query);
 
    while (qr.next())
    {
        projTable = qr.get(tablenum(ProjTable));
        print projtable.Name;
    }
 
    pause; 
}