report overlapping while running through code

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.

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