IBM Cognos 10 Report Studio Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

Dynamic links to an external website (a Google Maps example)

In this recipe, we will introduce you to the Hyperlink component.

Let's say that a report shows retailer information by products. It shows various fields like Retailer name, Contact information, City, and Postal zone. Business wants to have a link to Google Maps that will show a retailer's place on the map using the Postal zone information.

As the addresses might change in the backend, the technique needs to be dynamic to pick up the latest postal zone.

Getting ready

Create a simple list report that shows retailer information by Product lines as shown in the following screenshot:

How to do it...

In this recipe, we will add a hyperlink to the report that will open a Google map once you have clicked on it. To do this, perform the following steps:

  1. From the Toolbox, drag a hyperlink object onto the report as a new column as shown in the following screenshot:
  2. Change its Text property to Map. Set the URL Source Type to Report Expression and define the report expression as http://maps.google.com/maps?q=' + [Query1].[City (multiscript)] as shown in the following screenshot:
  3. Run the report to test it as shown in the following screenshot:

As you can see, there is a link for each retailer record. If you press Shift and click on the link, it will open Google Maps for the corresponding postal zone in a new window.

How it works...

Here we are using the Hyperlink component of Cognos Report Studio. We can define the URL as any static link.

However, for our requirements, we have defined a report expression. This allows us to provide a dynamic link which picks up the latest postal zone from the database. We are passing the postal zone to Google Maps as part of a URL.

The Hyperlink component works in HTML as well as Excel and PDF report formats. This object currently does not have the property to define whether the link target should open in a new window or the same window. Just clicking on the link opens the target in the same window, whereas pressing Shift and then clicking on the link opens the target in a new window.

There's more...

You can use this technique to call any external website that accepts parameters within a URL. You can pass multiple parameters too.