Home > Ax 2012, SSRS Reports > SSRS Tip: Prevent report execution through controller – Dynamics Ax 2012

SSRS Tip: Prevent report execution through controller – Dynamics Ax 2012

September 25, 2013 Leave a comment Go to comments

What a user might hate to see is a blank report. No matter where the mistake lies the earlier we react the happier the user is. Here today i’m sharing a tip on how you could stop/warn/show a info after the report execution is initiated  after the user clicks the “Ok” button in the dialog.

In the example discussed here, the idea is to check preemptively if a query will return a record or not. If no then the report aborts execution.

To implement this, open the controller of your report or create one.

On the controller class, override the method “preRunValidate”

Place the code as shown here. This method is invoked after the user clicks the “Ok” button and before the report is executed. Do not block the super call in this method as it does few other important validations. This method can return an error/warning/info. If it is a warning or error the report aborts further execution.

protected container preRunValidate()
{
    container   validateResult = super();
    Query       firstQuery;
    int         recordcount;

    firstQuery          = this.getFirstQuery();
    custStatementCount  = QueryRun::getQueryRowCount(firstQuery, 6);
    if (custStatementCount > 5)
    {
        validateResult = [SrsReportPreRunState::Error, "No valid records found for the specified range"];
    }

    return validateResult;
}

Standard recommends the method to be used for validating if the report returns a large amount of data.For reference see \Classes\CustAgingReportController\preRunValidate\
For more tips and learning about SSRS – AX 2012 order the book Dynamics AX 2012 Reporting Cookbook authored by me.

7720EN_MockupCover_Cookbook

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment