Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Problem with printing the correct packing slip report.

Posted on by 723
Hi,
I have a class that generates a SalesPackingSlip report and returns a stream which is then atached as a pdf file in an email.
The problem is that all the logic works fine until I get to the data provider class. The correct PackingSlipId value is passed in the method, but when I set the breakpoint to in the DP class, the PackigSlipId is different than what was passed in. As a result, the wrong document is attached in the email message
 
Can someone look at this, where is the error?
Thanks.
 
static System.IO.MemoryStream getReportByte(custInvoiceJour _custInvoiceJour)
    {
        SrsReportRunController srsReportRunController = new SrsReportRunController();
        SRSPrintDestinationSettings settings;
        custPackingSlipJour custPackingSlipJour;
        SalesPackingSlipContract contract = new SalesPackingSlipContract();
        Args args = new Args();
        CustPackingSlipTrans custPackingSlipTrans;
        CustInvoiceTrans custInvoiceTrans;
        System.IO.MemoryStream memoryStream;
        SRSReportRunService srsReportRunService = new SrsReportRunService();
        Map reportParametersMap;
        Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService.ParameterValue[] parameterValueArray;
        SRSProxy srsProxy;
        System.Byte[] reportBytes = new System.Byte[0]();
        SRSReportExecutionInfo reportExecutionInfo = new SRSReportExecutionInfo();
        SRSCatalogItemName reportDesignLocal;
        LanguageId languageId;
        Common printMgmtReferencedTable;
        FormLetterReport formLetterReport;
        PrintMgmtPrintSettingDetail printSettingDetail;
        PrintMgmtReportFormatName printMgmtReportFormatName = PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderPackingSlip).getDefaultReportFormat();
        reportDesignLocal = printMgmtReportFormatName;
    
        select firstOnly custInvoiceTrans 
            where custInvoiceTrans.SalesId == _custInvoiceJour.SalesId 
            && custInvoiceTrans.InvoiceId == _custInvoiceJour.InvoiceId
            && custInvoiceTrans.InvoiceDate == _custInvoiceJour.InvoiceDate 
            && custInvoiceTrans.numberSequenceGroup == _custInvoiceJour.numberSequenceGroup;

        select firstOnly custPackingSlipTrans 
            where custPackingSlipTrans.InventTransId == custInvoiceTrans.InventTransId;
    
        if(custPackingSlipTrans)
        {
            custPackingSlipJour = custPackingSlipJour::findFromCustPackingSlipTrans(custPackingSlipTrans.SalesId,custPackingSlipTrans.PackingSlipId,custPackingSlipTrans.DeliveryDate);
            SalesTable salesTable = custPackingSlipJour.salesTable();
 
            if (!reportDesignLocal)
            {
                reportDesignLocal = ssrsReportStr(MySalesPackingSlip, Report);
            }
            formLetterReport = FormLetterReport::construct(PrintMgmtDocumentType::SalesOrderPackingSlip);
            printMgmtReferencedTable = salesTable;
            languageId = salesTable.LanguageId ? salesTable.LanguageId : custPackingSlipJour.LanguageId;
            formLetterReport.loadPrintSettings(custPackingSlipJour, printMgmtReferencedTable, custPackingSlipJour.LanguageId);
 
            if (formLetterReport.moveNextPrintSetting())
            {
                printSettingDetail = formLetterReport.getCurrentPrintSetting();
                formLetterReport.parmReportRun().loadSettingDetail(printSettingDetail);
            }
            formLetterReport.parmPrintType(PrintCopyOriginal::Original);
            contract.parmRecordId(custPackingSlipJour.RecId);
            contract.parmTableId(custPackingSlipJour.TableId);
            contract.parmDocumentTitle('Packing slip);
            srsReportRunController.parmReportName(reportDesignLocal);
            srsReportRunController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
            srsReportRunController.parmShowDialog(false);
            srsReportRunController.parmReportContract().parmRdpContract(contract);
            srsReportRunController.parmReportContract().parmReportExecutionInfo(new SRSReportExecutionInfo());
            srsReportRunController.parmReportContract().parmReportServerConfig(SRSConfiguration::getDefaultServerConfiguration());
            settings = srsReportRunController.parmReportContract().parmPrintSettings();
            settings.printMediumType(SRSPrintMediumType::File);
            settings.fileFormat(SRSReportFileFormat::PDF);
            settings.overwriteFile(true);
            
            //memorystream 
            srsReportRunService.getReportDataContract(srsReportRunController.parmReportContract().parmReportName());
            srsReportRunService.preRunReport(srsReportRunController.parmreportcontract());
 
            reportParametersMap = srsReportRunService.createParamMapFromContract(srsReportRunController.parmReportContract());
            parameterValueArray = SrsReportRunUtil::getParameterValueArray(reportParametersMap);
 
            srsProxy = SRSProxy::constructWithConfiguration(srsReportRunController.parmReportContract().parmReportServerConfig());
            reportBytes = srsproxy.renderReportToByteArray(srsReportRunController.parmreportcontract().parmreportpath(), parameterValueArray, settings.fileFormat(), settings.deviceinfo());
 
            memoryStream = new System.IO.MemoryStream(reportBytes);
            //memorystream
        }
        return memoryStream;
    }
  • Shooowtek Profile Picture
    Shooowtek 723 on at
    Problem with printing the correct packing slip report.
    The problem was the DP class, which first searches for a CustPackingSlipVersion, and then searches for CustPackingSlipTrans based on the CustPackingSlipVersion.
     
    Therefore, the previously searched CustPackingSlipVersion should be put in contract.parmRecordId(), instead of CustPackingSlipTrans.
    This solved my problem.
  • Shooowtek Profile Picture
    Shooowtek 723 on at
    Problem with printing the correct packing slip report.
    Hi, thank you for your reply.
     
    CustPackingSLipTrans is searched for correctly. Only later when srsReportRunService.preRunReport() run and next the DP class is started, which gets wrong CustPackingSLipTrans record.. and I don't know why..
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,113 Super User 2024 Season 2 on at
    Problem with printing the correct packing slip report.
    Hi Shooowtek,
     
    You mentioned that a PackingSlipId is passed in a method. I can only see that this method accepts a CustInvoiceJour record. Thereafter you make some incorrect assumptions.
     
    You try to find a single packing slip transaction, where an invoice can contain transactions from multiple packing slips. Maybe this is not used in this way in your organization, but I would try to find all possible related packing slips, even if it would return one packing slip.
     
    Your first select statement for finding a CustInvoiceTrans record contains two obsolete fields. Due to that, it might be the case that no record is found. You can retrieve records with only the InvoiceID and InvoiceDate. That should be unique. Try to remove the other two fields from this select statement.
     
    In case I'm correct and it doesn't find a CustInvoiceTrans record, the next select statement to find a CustPackingSlipTrans record will return just the first record it can find regardless of an InventTransId. This because the CustInvoiceTrans.InventTransId field is empty if no record got returned for the CustInvoiceTrans table. To solve this issue, add an if-statement to check if the InventTransId field from the CustInvoiceTrans table has an actual value. Luckily you used the firstonly statement, otherwise it would load the whole table contents causing a performance issue.
    n
    I would also suggest using the debugger while executing the statements in this method to check at each step if the correct records are being retrieved from the database.
  • Shooowtek Profile Picture
    Shooowtek 723 on at
    Problem with printing the correct packing slip report.
    It looks like it is getting a random PackignSlipId.... I can't locate the cause of this issue.
     
    I would appreciate any suggestions.

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 Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,113 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,918 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans