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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Report Controller class caching

(0) ShareShare
ReportReport
Posted on by 35

Short Version :

If an error is thrown during the execution of an SSRS report after the associated RDP temporary tables have been updated, the next time the report is run for the same parameters, code execution does not insert fresh data into said tables. Any idea why and how to prevent it?

Long Version :

I am trying to modify the run conditions of a standard report (SalesInvoiceReport) so that the original of any invoice can only be printed once. For all reprints, the "Copy preview" option should be used.

For the most part, the customization is working as intended. I used the CustInvoiceJour.PrintedOriginals field and the CustInvoiceJour.updatePrintedOriginals() (both part of Standard Ax) to maintain the number of originals that have been printed and a slight modification to the SalesInvoiceController.outputReport() method throw an error of an original is being re-printed. Below is the code added to achieve this :

    //  <A147> Code to disable reprints if an original is already printed
    isOriginalPrintable = CustInvoiceJour::findRecId(custInvoiceJour.RecId).PrintedOriginals == 0;
    srsPrintDestinationSettings = formLetterReport.getCurrentPrintSetting().parmPrintJobSettings();
    //srsPrintMediumType          = srsPrintDestinationSettings.printMediumType();
    if ((printCopyOriginal == PrintCopyOriginal::Original || printCopyOriginal == PrintCopyOriginal::OriginalPrint))
    {
        // If no originals printed, allow prints.
        //      Need to re-read the CustInvoiceJour record from the table to get updated data
        //      If the Original is printed but the prin form is not refreshed, the form's recordset does not update to the latest data.
        if(isOriginalPrintable)
        {
            CustInvoiceJour::updatePrinted(custInvoiceJour, (srsPrintDestinationSettings.numberOfCopies() == 0 ? 1 : srsPrintDestinationSettings.numberOfCopies()));
        }
        // Don't allow the original document to be printed more than once.
        else
        {
            error(strFmt("@GLS223085", custInvoiceJour.InvoiceId, custInvoiceJour.InvoiceDate));
            return;
        }
    }
    //  </A147>

I placed this in the SalesInvoiceContreller.outputReport() because I found similar code present there as part of standard Ax, albeit for use in specific country regions.

When user uses the Original Preview button, the error is thrown and code execution stops but the RDP temporary tables used to hold the report data have already been updated with report data (specifically the field which hold the Report title is set to Invoice).

When the user reruns the report, this time with the Copy Preview button, code execution somehow skips inserting fresh data into the temp tables (which would set the Report Title field to Invoice Copy) and the first copy output still says Invoice, defeating the requirement.

Edit 1:

I made a short video of my investigation to better illustrate the issue. - https://youtu.be/dHOQ39SlOiU

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Sohaib Cheema Profile Picture
    47,776 User Group Leader on at
    RE: Report Controller class caching

    Hi 147,

    spend few minutes on debugging of useExistingReportData(method) of SalesInvoiceDP(Class)

    it may provide you something fishy

  • 147 Profile Picture
    35 on at
    RE: Report Controller class caching

    Hi,

    The error is the expected behavior - i.e. while originally designed for Hungary, my client wants this feature so I have activated it (simply made the Hungary code work by remove the check for CountryRegion). The error is not the issue.

    In the video, see the report titles. An Original Preview should have title "Invoice" and Copy Preview should have title "Invoice Copy".

    The execution run when Original Preview is clicked results in error (correct behavior) which instructs the user that an original has already been printed. Now the user goes to print the copy instead - the execution goes through (no error which is also correct), but the report title is "Invoice".

    The second part of the video show the possible reason. By the time the error is thrown during the first execution (Original Preview), the RDP temporary tables are already populated with the data expected from that run. That data is not consumed due to the error.

    Following this, the Copy Preview run does not insert any data into the temp tables. Instead it somehow knows that data already exists and chooses to use that data resulting in the incorrect report title.

    An error that is thrown does not clear the temp tables nor the subsequent execute independently. How can this be corrected?

  • Florian Hopfner Profile Picture
    2,451 on at
    RE: Report Controller class caching

    The error message in your video for Original Preview says "Invoice original has already been printed and will not be printed again." This seems to be a country specific error for Hungary (see method outputReport in class SalesInvoiceController). Either deactivate the configuration key for Hungary or make sure during tests that you are printing the invoice for the first time.

  • 147 Profile Picture
    35 on at
    RE: Report Controller class caching

    Hi Martin,

    I created a short video of my investigation showing the issue, as I find it a little to explain in words. https://youtu.be/dHOQ39SlOiU

  • Martin Dráb Profile Picture
    235,928 Most Valuable Professional on at
    RE: Report Controller class caching

    Can you tell us what's the error and where is it thrown?

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans