Walkthrough: Creating a Link from a Report to a Page

You can create reports that provide dynamic data with Visual Studio Report Designer and Microsoft Dynamics NAV 2009. Your reports can include images, graphics, toggles on data columns, interactive sorting, and links to other data in the system. This walkthrough illustrates how to set up a report to include a link to the customer card page. When the report is run in preview mode, you can look up any existing customer directly from the report. By including this functionality, you now have a report that is a dynamic list that you can use to drill down into data instead of a report that is a static, printed list.

About This Walkthrough

The walkthrough provides an overview of how to modify the Customer - Top 10 List report to include a link to the customer card. This walkthrough illustrates the following tasks:

  • Enabling hyperlinks on a report.

  • Adding a variable and code to the Customer - Top 10 List report definition.

  • Adding a text box to the Customer - Top 10 List report layout.

  • Adding a link to the customer name on the report using Visual Studio.

  • Running the modified report.

Prerequisites

To complete this walkthrough, you will need:

Before you can add a link from a report to a page, you must enable hyperlinks on the report. For more information, see EnableHyperlinks Property.

  1. In the Classic client, on the Tools menu, click Object Designer.

  2. In Object Designer, click Report, select report 111, the Customer - Top 10 List report, and then click Design.

  3. In Report Designer, select an empty line.

  4. On the View menu, click Properties.

  5. In the Properties window, in the EnableHyperlinks field, select Yes.

  6. Save and compile the report.

Adding a Variable and Code to the Report

In the following procedure, you will add a variable that holds a reference to the current customer record in the report.

To add a variable and code to the report

  1. In the Classic client, on the Tools menu, click Object Designer.

  2. In Object Designer, click Report, and then locate the Customer - Top 10 List report by typing object ID 111.

  3. Select the Customer - Top 10 List report, and then click the Design button.

  4. In Report Designer, select the Customer data item, and then on the View menu, click C/AL Globals.

  5. On the Variables tab, add a new entry. In the Name field, enter CustomerRecRef, and in the DataType field, select RecordRef.

  6. Close the C/AL Globals window.

  7. In Report Designer with the Customer data item still selected, on the View menu, click C/AL Code.

  8. In the C/AL Editor window, on the OnPreDataItem trigger, add the following line of code:

    CustomerRecRef.OPEN(18);
    
  9. In Report Designer, change focus to the Integer data item.

  10. In the C/AL Editor window, on the OnAfterGetRecord trigger, add the following line of code:

    CustomerRecRef.SETPOSITION(Customer.GETPOSITION);
    
  11. Close the C/AL Editor window and save the report.

Adding a Text Box to the Report

After creating the CustomerRecRef variable, you must create a new text box that is used to get the value of the current customer that is represented in the dataset in Visual Studio once the layout is opened there. The text box is not visible on the report when it is run but is only used for layout purposes. For more information, see How to: Resolve Formatting Issues Caused by Hidden Fields. The following steps illustrate how to add the text box to the report.

To add a text box to the report

  1. With the Customer - Top 10 List report open in Report Designer, on the View menu, click Sections.

  2. In Section Designer, locate the BarText text box, and then resize it to make room for a new small text box.

  3. On the View menu, click Toolbox.

  4. Click Textbox and then click on the report design to place it next to the BarText text box.

  5. Right-click the new Textbox, and then click Properties.

  6. In the Properties window, on the SourceExpr property, enter the following expression:

    FORMAT(CustomerRecRef.RECORDID,0,10)

  7. Close the Properties window.

    Note

    The usage of value 10 in this expression is a RoleTailored client feature only that will format RECORDID into a text representation that is compatible with the URL handler of reports and pages.

  8. Save and compile the report.

Once you have created the variable and text box with Report Designer, you can open and modify the layout of the report in Visual Studio. The following steps will add a link to the customer name on the report that opens the customer card for the selected customer. The text box that you created in Microsoft Dynamics NAV is part of the dataset in Visual Studio under Data Sources, and its value is referenced in the link you are adding.

  1. In the Classic client, with the Customer - Top 10 List report open in Report Designer, on the View menu, click Layout.

  2. In Visual Studio, in the Body section of the report, locate the Customer_Name text box. The value of the textbox is =Fields!Customer_Name.Value.

  3. Right-click the textbox, and then click Properties.

  4. In the Properties window, click the Navigation tab.

  5. Select the Jump to URL check box and enter the following line in the field below: ="dynamicsnav:////runpage?page=21&mode=edit&bookmark="+Fields!FORMAT_CustomerRecRef_RECORDID_0_10_.Value

    Note

    This line opens the page in edit mode.

  6. Click OK to close the window.

  7. Save the report in Visual Studio and return to the Classic client.

Running the Modified Report

In the Classic client, you must now save the modified report and compile it before it can be run.

To run the modified report

  1. In the Classic client, save the Customer - Top 10 List report. A message informs you that the .rdlc file for this report has changed and asks if you want to load the changes. Click Yes to save the changes in the database.

  2. On the Tools menu, click Compile to compile the report.

  3. On the Windows taskbar, click Start, and then click Run.

  4. In the Run window, enter the following text: dynamicsnav:////runreport?report=111, and then click OK.

  5. Click Preview to view the report. The report lists the top 10 list of customers. If you hover on the customer name, then you will get a link to open the specific customer on a separate customer card. This makes it possible to drill down into the customer's data.

See Also

Tasks

Walkthrough: Designing a Report with Images, Interactive Sorting, and Visibility Toggle
Walkthrough: Designing a Customer List Report
Walkthrough: Designing a Customer Sales Order Report
How to: Resolve Formatting Issues Caused by Hidden Fields