Monday, 19 August 2019

Generate report through X++ and save as pdf in to folder EX:SalesInvoiceReport +D365


SrsReportRunController   controller = new SrsReportRunController();

        SalesInvoiceContract     rdpContract = new SalesInvoiceContract();
        SRSPrintDestinationSettings   settings;
        System.Byte[]    reportBytes = new System.Byte[0]();
        SRSProxy    srsProxy;
        SRSReportRunService    srsReportRunService = new SrsReportRunService();
        Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[]   parameterValueArray;
        Map  reportParametersMap;
        SRSReportExecutionInfo       executionInfo = new SRSReportExecutionInfo();
        ;
        CustInvoiceJour custInvoiceJour = CustInvoiceJour::findFromSalesId_IN("SO081204");
        if(custInvoiceJour)
        {
            if (!WinAPI::pathExists("C:\\Temp\\Invoices\\"))
                WinAPI::createDirectoryPath("C:\\Temp\\Invoices\\");

            Filename filename =strfmt("C:\\Temp\\Invoices\\%1%2",custInvoiceJour.InvoiceId,".pdf");

            controller.parmReportName(ssrsReportStr(SalesInvoice, Report));
            controller.parmShowDialog(false);// Explicitly provide all required parameters
            rdpContract.parmRecordId(custInvoiceJour.RecId);
            controller.parmReportContract().parmRdpContract(rdpContract);// Change print settings as needed
            settings = controller.parmReportContract().parmPrintSettings();
            settings.printMediumType(SRSPrintMediumType::File);
            settings.fileFormat(SRSReportFileFormat::PDF);
            settings.overwriteFile(true);
            settings.fileName(filename);
            controller.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
            controller.parmReportContract().parmReportExecutionInfo(executionInfo);
            srsReportRunService.getReportDataContract(controller.parmreportcontract().parmReportName());
            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());

            if (reportBytes)
            {
                System.IO.Stream            stream         = new System.IO.MemoryStream(reportBytes);
                var fileStream = new System.IO.FileStream(filename, System.IO.FileMode::Create, System.IO.FileAccess::ReadWrite);
                stream.CopyTo(fileStream);

            }
        }


==========================================================================
http://www.dnetsoft.com/en-us/d365-generate-a-report-through-x-and-save-in-a-local-folder/

4 comments:

  1. I will recommend anyone looking for Business loan to Le_Meridian they helped me with Four Million USD loan to startup my Quilting business and it's was fast When obtaining a loan from them it was surprising at how easy they were to work with. They can finance up to the amount of $500,000.000.00 (Five Hundred Million Dollars) in any region of the world as long as there 1.9% ROI can be guaranteed on the projects.The process was fast and secure. It was definitely a positive experience.Avoid scammers on here and contact Le_Meridian Funding Service On. lfdsloans@lemeridianfds.com / lfdsloans@outlook.com. WhatsApp...+ 19893943740. if you looking for business loan.

    ReplyDelete
  2. Do you need Finance? Are you looking for Finance? Are you looking for finance to enlarge your business? We help individuals and companies to obtain finance for business expanding and to setup a new business ranging any amount. Get finance at affordable interest rate of 3%, Do you need this finance for business and to clear your bills? Then send us an email now for more information contact us now via (financialserviceoffer876@gmail.com) whats-App +918929509036 Dr James Eric Finance Pvt Ltd Thanks

    ReplyDelete
  3. DEAR APPLICANT,

    We offer Affordable loan at 3% interest rate available for local and international borrowers. We are certified,trustworthy, reliable, efficient, Fast and dynamic and a co-operate financier for real estate and any kinds of business financing,we offer the following:* Personal Loans * Student Loan * Business Loans * Consolidation Loan * Combination Loan* *Home Enhancement* Car Loan *Construction Loan e.t.c

    We are Christian organization founded, people in needs of assistance helps, such as financial help. So, if you go through financial difficulties or you are in any financial mess, and you need funds, to start you need your own business, or you need a loan to pay off your debts or pay your bills, start a nice business, or you will find it difficult, to obtain capital loan from local banks, for the Bible says , "" Anyone who asks, receives Luke 11.10, and who seeks, finds, and who knocks on the door, the door will be opened ", so do not miss this chance, because Jesus is the same yesterday, today, and forever more. Please this is for serious minded and God-fearing people.

    Fill the application form below for further information.

    Full Name:___________
    Sex:________
    Age:______
    Country:__________
    Address___________
    State: ________
    Tel:______
    Occupation: __________
    Monthly Income:___________
    Loan Amount Needed ($) :__________
    Amount in Words:
    Loan Duration:__________
    Pan Card or Voters Id No:__________

    We await your responds

    Regards
    Trust Bridge Financial Service
    E_mail: trustbridgefinancialservice943@yahoo.com

    ReplyDelete