Visual Studio Design Expressions (Specific to AX SSRS Reports)

Visual Studio Design Expressions (Specific to AX SSRS Reports)

Microsoft Dynamics AX utilizes SSRS for its reporting needs. The layout of a SSRS report is based upon its design, which is created in Microsoft Visual Studio. Visual Studio designs offer a magnitude of flexibility when it comes to how the report can be displayed. At times, it may be necessary to change the layout of the report based off of user input data. In this tutorial, we’ll look at how this can be accomplished using Visual Studio design expressions.

*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.

Figure 1.0 shows 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.

Figure 1.0: Dialog for a SSRS report displaying invoices and/or orders by vendor for a specific customer

As a quick example, we are going to change this textbox emphasized in Figure 2.0. The textbox will display different strings depending on which “Invoice/Order Account” option the user picks.

Figure 2.0: Change this textbox emphasized

Figure 2.1: Expression value setup

Right click the text box and then select expression to get to Figure 2.1. 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)

Above, 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”.

It is important to 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.)

Figure 3.0:

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.

Figure 4.0: Text Box Properties

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.

Figure 4.1: Selecting the ‘fx’ visibility icon

Figure 4.2: Constants expression

The visibility expression can be modified here. 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.

Share on Google+Tweet about this on TwitterShare on LinkedInShare on FacebookEmail this to someone