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, ...
Suggested Answer

Print a report in the background as a PDF

(2) ShareShare
ReportReport
Posted on by 58
Hi,
 
In a processing class, I print an invoice image in PDF format, which I send via email.
Printing is done directly to memory:
 
        // Actual rendering to byte array
        srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
        reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),
                                        parameterValueArray,
                                        settings.fileFormat(),
                                        settings.deviceinfo());
 
However, during background processing, the following window appears.
Couldn't this processing window be hidden somehow?
 
Environment: D365 FnO Kernel 10.0.45
 
Thank you in advance.
 
Regards,
László
 
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    238,753 Most Valuable Professional on at
    I can't see the picture. Please either share it again or describe what you see in the window.
     
    Also, what exactly do you mean by background processing. That you send it to batch server. Or that you run it with Asynchronous execution mode (or so)?
  • Anton Venter Profile Picture
    20,635 Super User 2026 Season 1 on at
    @LH-16011234-0 can you insert the image using the toolbar Image button? Your image was somehow not saved in your post.
     
    I don't have experience with SRSProxy. Have you tried to debug your code to see where it's showing the dialog? Perhaps there is a parameter to disable? Like parmShowDialog(false) or something.
     
    I have this F&O example to print SRS reports from code (author unknown). I have not tested it but it should work. Perhaps this helps.
     
    SrsReportRunController          controller = new SrsReportRunController();
    SysUserLicenseCountRDPContract  rdpContract = new SysUserLicenseCountRDPContract();
    SRSPrintDestinationSettings     settings;
     
    controller.parmReportName(ssrsReportStr(SysUserLicenseCountReport, Report));
    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
    controller.parmShowDialog(false);
    
    rdpContract.parmReportStateDate(systemDateGet());
    controller.parmReportContract().parmRdpContract(rdpContract);
    
    settings = controller.parmReportContract().parmPrintSettings();
    settings.printMediumType(SRSPrintMediumType::File);
    settings.fileFormat(SRSReportFileFormat::Excel);
    settings.fileName('licnt.xlsx');
     
    controller.startOperation();
     
  • LH-16011234-0 Profile Picture
    58 on at
    I hope the picture appears now.
    Current method:
     
        public System.Byte[] saveCustInvoiceAsPDF(CustInvoiceJour _custInvoiceJour, FileName _fileName)
        {
            #ISOCountryRegionCodes
            Args                            args = new Args();
            SalesInvoiceController          controller = SalesInvoiceController::construct();
            SalesInvoiceContract            contract;
            ReportName                      reportName = PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat();
            System.Byte[]                   reportBytes = new System.Byte[0]();
            SRSPrintDestinationSettings     settings;
            SRSProxy                        srsProxy;
            SRSReportRunService             srsReportRunService = new SrsReportRunService();
            Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[]  parameterValueArray;
            Map                             reportParametersMap;
            SRSReportExecutionInfo          executionInfo = new SRSReportExecutionInfo();
            args.record(_custInvoiceJour);
            args.parmEnumType(enumNum(PrintCopyOriginal));
            args.parmEnum(PrintCopyOriginal::Original);
            // Provide details to controller and add contract
            controller.parmReportName(reportName);
            controller.parmShowDialog(false);
            controller.parmLoadFromSysLastValue(false);
            controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
            controller.parmArgs(args);
            contract = controller.parmReportContract().parmRdpContract() as SalesInvoiceContract;
            contract.parmRecordId(_custInvoiceJour.RecId);
            contract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
            contract.parmPrintCopyOriginal(PrintCopyOriginal::Original);
            // Provide printer settings
            settings = controller.parmReportContract().parmPrintSettings();
            settings.printMediumType(SRSPrintMediumType::File);
            //Change file extension or add a new parameter to function
            settings.fileName(_fileName);
            settings.fileFormat(SRSReportFileFormat::PDF);
            // Below is a part of code responsible for rendering the report
            controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
            controller.parmReportContract().parmReportExecutionInfo(executionInfo);
            srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
            //srsReportRunService.DAX_ParmSuppressRdpExecutionFlagSet(true);
            srsReportRunService.preRunReport(controller.parmreportcontract());
            reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract());
            parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);
            srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
            // Actual rendering to byte array
            reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),
                                            parameterValueArray,
                                            settings.fileFormat(),
                                            settings.deviceinfo());
            return reportBytes;
        }
     
     
    2025-12-02_7-32-20.png
  • Suggested answer
    Komi Siabi Profile Picture
    13,190 Most Valuable Professional on at
    public System.Byte[] saveCustInvoiceAsPDF(CustInvoiceJour _custInvoiceJour, FileName _fileName)
    {
        #ISOCountryRegionCodes
        Args                            args = new Args();
        SalesInvoiceController          controller = SalesInvoiceController::construct();
        SalesInvoiceContract            contract;
        ReportName                      reportName = PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat();
        System.Byte[]                   reportBytes = new System.Byte[0]();
        SRSPrintDestinationSettings     settings;
        SRSProxy                        srsProxy;
        SRSReportRunService             srsReportRunService = new SrsReportRunService();
        Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[]  parameterValueArray;
        Map                             reportParametersMap;
        SRSReportExecutionInfo          executionInfo = new SRSReportExecutionInfo();
        args.record(_custInvoiceJour);
        args.parmEnumType(enumNum(PrintCopyOriginal));
        args.parmEnum(PrintCopyOriginal::Original);
        // Provide details to controller and add contract
        controller.parmReportName(reportName);
        
        controller.parmLoadFromSysLastValue(false);
        controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);
        controller.parmArgs(args);
        contract = controller.parmReportContract().parmRdpContract() as SalesInvoiceContract;
        contract.parmRecordId(_custInvoiceJour.RecId);
        contract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo());
        contract.parmPrintCopyOriginal(PrintCopyOriginal::Original);
     
        //RUN THE REPORT
        controller.parmShowDialog(false);
        controller.runReport();
        //RUN THE REPORT - END
    
        // Provide printer settings
        settings = controller.parmReportContract().parmPrintSettings();
        settings.printMediumType(SRSPrintMediumType::File);
        //Change file extension or add a new parameter to function
        settings.fileName(_fileName);
        settings.fileFormat(SRSReportFileFormat::PDF);
        // Below is a part of code responsible for rendering the report
        controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
        controller.parmReportContract().parmReportExecutionInfo(executionInfo);
        srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
        //srsReportRunService.DAX_ParmSuppressRdpExecutionFlagSet(true);
        srsReportRunService.preRunReport(controller.parmreportcontract());
        reportParametersMap = srsReportRunService.createParamMapFromContract(controller.parmReportContract());
        parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);
        srsProxy = SRSProxy::constructWithConfiguration(controller.parmReportContract().parmReportServerConfig());
        // Actual rendering to byte array
        reportBytes = srsproxy.renderReportToByteArray(controller.parmreportcontract().parmreportpath(),
                                        parameterValueArray,
                                        settings.fileFormat(),
                                        settings.deviceinfo());
        return reportBytes;
    }
     
     
    Two things, 
    controller.parmShowDialog(false) - To suppress the dialog , which you already have 
    and 
    controller.runReport(); to run the report before rendering the bytes.
  • LH-16011234-0 Profile Picture
    58 on at
    Hi,
     
    Unfortunately, the proposed solution is not good.
     
        //RUN THE REPORT
        controller.parmShowDialog(false);
        controller.runReport();
        //RUN THE REPORT - END
    "controller.parmShowDialog(false);" was already included.
    I get the following error when I run "controller.runReport();": "Parameter executionInfo cannot be null or empty."
     
    Regards,
    László
     
  • Komi Siabi Profile Picture
    13,190 Most Valuable Professional on at
    I moved your controller.parmShowDialog(false);
     
    Can you tell me where you are you running your method from ?
     
    I had used your exact code to send our report in PDF while on a record. 

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 375

#3
Adis Profile Picture

Adis 268 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans