Tuesday, November 28, 2017

Saving a Dynamics Ax Report to PDF

Hi guys!

I am gonna show you how to save a Dynamics Ax Report to PDF file.

We are going to use de getTempPath() method from WinApi class for getting the tmp directory.

static void saveProdId()
{
    ReportRun report;
    Args args;
    ProdBOM prodBOM;
    FilePath  path;
   ProdId  prodId;
    ;

    path = WinAPI::getTempPath();
    prodId= 'ProdIdNumber';

    select prodBOM where prodBOM.ProdId == prodId
            && prodBOM.ProdLineType == BomType::Vendor;


    args =  new Args();
    args.name(reportStr(SomeReport));
    args.record(prodBOM);
    report = ClassFactory.reportRunClass(args);
    report.printJobSettings().setTarget(PrintMedium::File);
    report.printJobSettings().preferredTarget(PrintMedium::File);
    report.printJobSettings().format(PrintFormat::PDF);
    report.printJobSettings().fileName(path + prodId  + '.pdf');
    report.query().interactive(false);
    report.run();


}

See you!

No comments:

Post a Comment