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 :
Dynamics 365 Community / Forums / Finance forum / Print report via x++
Finance forum

Print report via x++

(0) ShareShare
ReportReport
Posted on by

Hey - i am trying to print a report to a PDF file in a local directory.

There are many working examples for AX2012 and if you copy the code everything is working except that ax downloads the PDF in the Browser instead of saving a PDF in a directory.

My goal is to stream a SalesInvoice Report via webserivce.

What we used to do in 2012:

1) generate the Report and save it t c:\temp\xyz.pdf

2) read the file and pass the content to the AIF

3) delete the file

The used code is not working anymore in AX 365 - it keeps telling me that the file does not exist.

So I created a runnable class:

class TestPrintJob
{        
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        Args                            args;

        ContactPerson                   contactPerson;
        SrsReportRunController          controller;
        SRSPrintDestinationSettings     srsPrintDestinationSettings;
        CustTable                       custTable;
        CustInvoiceJour                 custInvoiceJour = custInvoiceJour::findRecId(5637163320);
        SalesTable                      salesTable;
        SalesInvoiceContract            rdpContract;
        System.Byte[]                   pdfDocBuffer;
        System.IO.FileInfo              fi_pdfDoc;
        System.IO.FileStream            fs;
        guid                            myGuid;
        str                             pdfString = '',
                                        savedFile,
                                        filePath,
                                        myGuidStr,
                                        reportPath;


        if (custInvoiceJour.RecId != 0)
        {

            myGuid = newguid();
            myGuidStr = guid2str(myGuid);

            controller = new SrsReportRunController();

            controller.parmReportName(ssrsReportStr(SalesInvoice, Report));
            controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
            controller.parmShowDialog(false);
            controller.objectOnServer();

            rdpContract  = new SalesInvoiceContract();
            rdpContract.parmRecordId(custInvoiceJour.RecId);
            rdpContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
            rdpContract.parmDocumentTitle("@SYS14204");

            // (1) Try by passing args
            args = new Args();
            args.record(custInvoiceJour);
            args.parmEnum(PrintCopyOriginal::OriginalPrint);
            args.parmEnumType(enumNum(PrintCopyOriginal));

            controller.parmReportContract().parmRdpContract(rdpContract);
            controller.parmArgs(args);

            // Change print settings as needed
            srsPrintDestinationSettings = controller.parmReportContract().parmPrintSettings();
            srsPrintDestinationSettings.printMediumType(SRSPrintMediumType::Custom);
            srsPrintDestinationSettings.fileFormat(SRSReportFileFormat::PDF);
            srsPrintDestinationSettings.overwriteFile(true);

            filePath = @'c:\tmp\InvoiceReport_' + myGuidStr + '.pdf';

            srsPrintDestinationSettings.fileName(filePath);

            controller.startOperation();

        }

    }

}


If I run the job AX is rendering the Report and it gets downloaded instantly while C:\tmp stays empty.

I cant figure out why the old way is not working anymore.

Is there any way to save the report to a file or in a string?

Thanks in advance - Alex

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    D365FO in the cloud has no way of seeing your local directories. So it's not possible to print to a local directory.

    For sure you may be able to print to a local directory on the VM but what would be the business value? In prod, you can't access it anyway.

    Unless you are working with the on premises version of D365FO. Is that the case?

  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    Hi Alex,

    You can print report to memory stream or byte array and then send it, here is an example http://www.meritsolutions.com/render-report-memory-stream-d365-aka-ax7/

    So you can avoid extra step to save file and then read it. 

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

    You could create a custom controller which would send the file to a web service instead of returning it to the user.

    Note that AIF doesn't exist anymore.

  • Suggested answer
    Community Member Profile Picture
    on at

    Wow - thank you! I already tried it and it seems to work fine.

  • Community Member Profile Picture
    on at

    Hey Martin - the solution with the memory stream seems to be a faster approach.  Thanks anyways.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans