Microsoft Dynamics AX utilizes SSRS for reporting needs. The layout of a SSRS report is based upon its design created in Microsoft Visual Studio. Visual Studio designs offer a magnitude of flexibility when it comes to how the report can be displayed. This tutorial, looks at how this is accomplished using Visual Studio design expressions.
Using Visual Studio
It’s important to note that Microsoft Dynamics AX 2012 R2 and Visual Studio 2010 are being used in this tutorial. The process may be different with other software versions.
Look at the dialog for a SSRS report displaying invoices and/or orders by vendor for a specific customer. While this report contains a number of parameters, the main focus for this example is the “Invoice/Order Account”. Essentially, the customer can choose to either view the report in respect to the invoices, the orders, or a combination of both. Because only the format is changing, and the data will remain fundamentally the same, one Visual Studio report design can be used alongside layout expressions to complete the report.
Practice by changing a textbox emphasized. The textbox will display different strings depending on which “Invoice/Order Account” option the user picks. Right click the text box and then select expression.
For this expression, we will use a ternary operator. The format in Visual Studio for a ternary operator is the following: IIF(condition, result, result if condition is not met)
The ternary operator states that if the “Invoice/Order Account” parameter (brought in by the dataset) is set to “InvoiceAccount”, set the textbox string to “Invoice Account”. Otherwise, set the textbox string to “Order Account”. “Order Account” will be displayed in the textbox if the user selects “OrderAccount” or “InvoiceOrder”.
Note that the “Invoice/Order Account” parameter is based off of an AX enum whose values are the following: 0:InvoiceAccount, 1:OrderAccount, 2:InvoiceOrder. In Visual Studio, the ternary operator uses the identifying string instead of the actual enum value, which is why we have used “InvoiceAccount” rather than 0. (This also applies to NoYes enums: use “No” or “Yes” instead of 0 or 1.)
Expression and Effect
After saving, building, and deploying the report from Visual Studio, we can see the expression in effect. Both images are for the customer account: “100008”. In the first image, “Invoice Account” has been selected and “Invoice Account” displays. In the second image, “Order Account” has been selected and “Order Account” displays. “Order Account” also displays if “Invoice/Order” had been selected.
Expressions can be used for textbox, row, column, or table group visibility as well. In order to get to the visibility expression, select the object and right click. Then select, “Text Box Properties…”. Go to the “Visibility” section and then select, “Show or hide based on an expression”.
To edit the expression, select the “fx” icon. The visibility expression can be modified. By default, the expression should be constructed so that if true, the object is HIDDEN.
Both of these functionalities are very helpful in making SSRS reports more dynamic without the necessity of multiple report designs.
If you have questions about visual studio design expression in Dynamics AX SSRS reports, contact us.