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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Print Report to file and stream via AIF

(0) ShareShare
ReportReport
Posted on by

Hey,

Iam having trouble with printing a report via AIF (http).

We use the following code (simple example):

        args = new Args(reportStr(SalesInvoice));
        args.record(custInvoiceJour);
        args.parmEnum(PrintCopyOriginal::Original);
        // need to say ReportRun not to change PrintJobSettings in fetch-method
        args.parm(settings);

        reportRun = new ReportRun(args);
        reportRun.report().interactive(false);
        reportRun.query().interactive(false);

        printJobSettings = new PrintJobSettings();
        printJobSettings.format(PrintFormat::PDF_EMBED_FONTS);
        printJobSettings.setTarget(PrintMedium::File);
        printJobSettings.warnIfFileExists(false);
        printJobSettings.suppressScalingMessage(true);
        printJobSettings.preferredFileFormat(PrintFormat::PDF_EMBED_FONTS);
        fileName = strfmt('\\\\Test-Server\\Transfer\\Test2.pdf');
        printJobSettings.fileName(fileName);

        reportRun.printJobSettings(printJobSettings.packPrintJobSettings());
        reportRun.init();
        reportRun.run();

        // send created PDF as byte stream
        // Grant clrinterop permission.
        new InteropPermission(InteropKind::ClrInterop).assert();
        //Load the file
        fi_pdfDoc = new System.IO.FileInfo(fileName);
        //Initiallize the byte array by setting the length of the file
        pdfDocBuffer= new System.Byte[int642int(fi_pdfDoc.get_Length())]();
        // Stream the file
        fs= new System.IO.FileStream(fi_pdfDoc.get_FullName(), System.IO.FileMode::Open, System.IO.FileAccess::Read);
        fs.Read(pdfDocBuffer, 0, pdfDocBuffer.get_Length());
        // Convert the file into a base64 string
        content = System.Convert::ToBase64String(pdfDocBuffer, 0, pdfDocBuffer.get_Length());
        //Revert the access
        CodeAccessPermission::revertAssert();
        return content;

We want to print old reports - this code works pretty well on AX 2009 - with old reports.

If Iam trying to print a SSRS-Report everything is fine. For some reson the old reposts wont work on 2012.

The following error is shoing up:

SoapFault exception: [s:Client] ClassFactory Objekt ist nicht initialisiert.

Stack-Trace

(S)\Classes\LedgerCache\getValue - line 3
(S)\Data Dictionary\Tables\Ledger\Methods\current - line 13
(S)\Data Dictionary\Tables\Currency\Methods\mstAmount - line 13
(S)\Classes\TaxInvoiceSpec\taxSpec - line 399
(S)\Reports\VendInvoiceSpec\Methods\fetch - line 33
(S)\Classes\ReportRun\Run
(S)\Jobs\

Are there any ideas? I tried different reports - I dont think the probem is the report itself.

If I run the code serverside (not via AIF) the report is printed without any problems.

Thank you very much.

*This post is locked for comments

I have the same question (0)
  • Mariano Gracia Profile Picture
    on at

    Have you tried to run it in a batch job?, AIF and batch jobs are executed on CIL

  • Community Member Profile Picture
    on at

    No, not yet.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Assuming that "old" reports mean MorphX reports, note that they aren't supported anymore in AX 2012 and you shouldn't use them. If you still have MorphX reports, it's time to finish your code upgrade to AX 2012 and convert them to SSRS reports.

  • Suggested answer
    Brian Kinser Profile Picture
    815 on at

    I have done this before: Write code that will run older Morph X reports by writing out to a file.......some reports work and some don't depending on how they get spun up....SalesInvoice you may have trouble with because it uses the active record from CustPackingSlipJour. I see that you are passing the row but LedgerCache probably has no data in it. It will be better to just upgrade the SalesInvoice report I think

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans