Saturday, 30 November 2013

How to handle SSRS reports which will take long time to run with the messages to the user [Dynamics AX 2012– preRunValidate() method]

How to handle SSRS reports which will take long time to run with the messages to the user [Dynamics AX 2012– preRunValidate() method]


We know that there are/will be some reports which will take more time to render due to the many rows/transactions. This post will help you to show appropriate warning/error messages to the end user while running the report.
The number of records that are processed by report might be large and the user experience will be affected, because the client will be locked up if printing to the screen. [msdn]
In this case, you might want to return a warning message to the user that indicates that time to process the report might be long and confirm that they want to run the report. [msdn]
Another case could be where the number of records being processed is very large and a time-out might occur in report processing and clearly we should not run this report. [msdn]
In this case, we should not run the report and therefore, should return an SrsReportPreRunState::Error enumeration value with the error message.
In AX 2012, SSRS reports , through SrsReportRunController we can easily let the user know that the report will take more time with warnings or error messages through preRunValidate method.
Example : General Journals report
Let me take the standard example of Print journal from General Ledger >> Reports >> Journal >> Print journal.
I am using standard LedgerJournalController class to help you understand preRunValidate method: this validates container before running the report. We have to override this method to do custom pre-validation for any report. Typical use of this method will be to validate if the time taken to run the report is acceptable.
In this standard example: If the query is going to retrieve more than 1000 rows, a confirmation Box will be displayed to the user as shown below.
To get the confirmation box and for the sake of the demo/understanding: I have hardcoded the rows count to 1001 as shown below. There is a new static method in QueryRun::getQueryRowCount that will get the row Count of the query.
Please note: Remove hardcoded values later. This is hardcoded only for the sake of demo/Walk through
Clearly in the below standard example : warning limit is 1000 and error limit is 100000. However this is customizable based on your requirement.
image
Now let us run this report as shown below : Click on the Ok Button.
image
Here comes the confirmation Box: If your report is long running, it may time-out. Do you want to continue?
In order to resolve/by pass this confirmation Box, a developer can change the macro #define.warningLimit to greater value
Example : #define.warningLimit(2000);
image
Now lets increase the row count : to 1000001.
Please note: Remove hardcoded values later. This is hardcoded only for the sake of demo/Walk through
image
Let us run the report One more time as shown below.
image
Here comes the error message: Running the report has been cancelled due to the time it will take to run. Adjust the parameters of the report and retry.
In order to resolve this problem, Increase the ErrorLimit macro value in the preRunValidate method.
Please note, it is not recommended to increase as it will take more time and your box cannot handle load.
Example : #define.ErrorLimit(150000);
image
That’s it for now.

No comments:

Post a Comment