Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

report overlapping while running through code

(0) ShareShare
ReportReport
Posted on by 2,953

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
    krishna.rao@dax 2,953 on at
    RE: report overlapping while running through code

    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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans