web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Active Discussion

report overlapping while running through code

(0) ShareShare
ReportReport
Posted on by 3,008

Hi Peers,

In AX 20009, we are running report "Project invoice"  through code. when we are doing with code getting issue of data over lapping in report.

There is no issue if we are opening same report from project invoice journal form.

Below is the code.

#EInvoicePDFNodes
ReportRun report;
FilePath filePath = EInvoiceParameters_IT::find().PdfInvoice;
FileName fileName;
PrintJobSettings settings;
ProjPrintInvoice printInvoice;
Args args;
Set permissionSet;
;
printInvoice = new ProjPrintInvoice();
args = new Args(ReportStr(projInvoice));
args.caller(printInvoice);
args.record(projInvoiceJour);

report = new ReportRun(args);

filename = filePath+projInvoiceJour.ProjInvoiceId+".pdf";
permissionSet = new Set(Types::Class);
permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
permissionSet.add(new FileIOPermission(projInvoiceJour.ProjInvoiceId+".pdf", "w"));
CodeAccessPermission::assertMultiple(permissionSet);
if (System.IO.File::Exists(fileName))
{
System.IO.File::Delete(projInvoiceJour.ProjInvoiceId+".pdf");
}
CodeAccessPermission::revertAssert();
settings = report.printJobSettings();
settings.setTarget(PrintMedium::File);
settings.preferredTarget(PrintMedium::File);
settings.format(PrintFormat::PDF);
settings.preferredFileFormat(PrintFormat::PDF);
settings.viewerType(ReportOutputUserType::PDFEmbedFonts);
settings.doNotOverwrite(true);
settings.fileName(fileName);
settings.lockDestinationProperties(true);
printInvoice.updatePrinterSettingsPrintInvoice(settings.packPrintJobSettings());
report.unpackPrintJobSettings(settings.packPrintJobSettings());
report.run();

No issue if same report is running from user interface . Project -> Inquiries -> invoice -> Invoice -> show button - choose Origin

Can you please help here is anyone fixed similar issue, find below screenshots for reference.

8561.ProjectInvoiceReport_5F00_Forum.png

  • krishna.rao@dax Profile Picture
    3,008 on at

    Below is the code which worked.

    Args args;
    ReportRun reportRun;
    Report report;
    PrintJobSettings printJobSettings;
    FilePath filePath = EInvoiceParameters_IT::find().PdfInvoice;
    FileName fileName;
    Set permissionSet;
    ProjPrintInvoice projPrintInvoice;
    ;

    if (!filePath)
    {
    throw error("@PRG1034");
    }

    projPrintInvoice = new ProjPrintInvoice();

    args = new Args(ReportStr(projInvoice));

    args.record(projInvoiceJour);
    args.caller(projPrintInvoice);
    args.parmEnum(PrintCopyOriginal::Original);

    // Set report run properties
    reportRun = new ReportRun(args,'');
    reportRun.suppressReportIsEmptyMessage(true);
    reportRun.query().interactive(false);

    // set report properties
    report = reportRun.report();
    report.interactive(false);

    //file permissions
    filename = filePath + projInvoiceJour.ProjInvoiceId+ ".pdf";
    permissionSet = new Set(Types::Class);
    permissionSet.add(new InteropPermission(InteropKind::ClrInterop));
    permissionSet.add(new FileIOPermission(projInvoiceJour.ProjInvoiceId+".pdf", "w"));
    CodeAccessPermission::assertMultiple(permissionSet);
    if (System.IO.File::Exists(fileName))
    {
    System.IO.File::Delete(projInvoiceJour.ProjInvoiceId+".pdf");
    }
    CodeAccessPermission::revertAssert();

    // set print job settings
    printJobSettings = reportRun.printJobSettings();
    printJobSettings.fileName(fileName);
    printJobSettings.fitToPage(true);
    // break the report info pages using the height of the cureportRunent printer's paper
    printJobSettings.virtualPageHeight(-1);


    // force PDF printing
    printJobSettings.format(PrintFormat::PDF);
    printJobSettings.setTarget(PrintMedium::File);
    printJobSettings.viewerType(ReportOutputUserType::PDF);

    // lock the print job settings so can't be changed
    // X++ code int the report may try to change the destination
    // to the screen for example but this does not make
    // sense when running a report here
    printJobSettings.lockDestinationProperties(true);

    //printJobSettings.warnIfFileExists(false);//TODD: newly added
    printJobSettings.doNotOverwrite(true);//TODD: newly added

    // Initialize the report
    reportRun.init();

    projPrintInvoice.updatePrinterSettingsPrintInvoice(printJobSettings.packPrintJobSettings());

    reportRun.unpackPrintJobSettings(printJobSettings.packPrintJobSettings());

    reportRun.run();

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 733

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 278 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans