Monday, November 18, 2013

How to launch a SSRS report (with some parameters) from AX 2009

Hi folks!

I will show you how to create a CommandButton in a form able to launh a SSRS report in Report Viewer from AX 2009 with parameter passing.

Picture yourself that we have a SSRS report with a parameter called "test", and this parameter must be taken from the datasource table of the form.

All you have to do is create a CommandButton control in your form and override the "clicked" method with this code:

void clicked()
{
    //declare the parameter
    str          _test;
    ;

    //assign to the parameter the value of the datasource field
    _test      = YourTableName.YourFieldName;
    infoLog.urlLookup(
    strfmt("http://<yourServername>/<yourReportWebServiceName>/Pages/ReportViewer.aspx?/<yourReportName>&rs:Command=Render&<Test>=%1",_test));

    super();
}

This command will open your browser and automatically launch the report with the specified parameter.

Sometimes I noticed visualization problems with browser different from Internet Explorer.
If Internet Explorer isn't the default browser, just change the command "infolog.urlLookup()" with:

WinAPI::shellExecute("iexplore.exe",strfmt("http://<yourServername>/<yourReportWebServiceName>/Pages/ReportViewer.aspx?/<yourReportName>&rs:Command=Render&<Test>=%1",_test),"","",1);

That's all!


No comments:

Post a Comment