Running Cognos Reports Using A Url
Running Cognos Reports Using A Url
By Dave Munson, Sr. Developer, BSP Software Inc. About Us Who We Are What We Do What We Believe Cognos Resellers Newsletters News Archive Location Careers Contact
Running a Cognos report requires several pieces of information. First, it needs to know where the report is located. Then it needs to know if you want to run the report or view saved output, and in which format. If you want it to run the report, what should it do with the output? Save it? Show it? Email it? And finally it will need values for any report prompts. This is just a sample of the information the Cognos server needs before it can run a report. And so far you are required to use Cognos interfaces to change them. But what if you wanted to run the report and supply all, or some of those values yourself?
Cognos, for the most part, is a web application, and thus uses standard web application methodologies such as POST and GET to pass parameters around. Cognos uses a single application (usually Cognos.cgi or cognosisapi.dll) for nearly all of its interfaces. Depending on what parameters are passed to this application it generates different web pages. These pages might be Cognos connection folder contents, admin screens or reports to name a few. In many cases Cognos passes these parameters around by embedding them in hyperlinks. This is done by adding a querystring to the URL of the hyperlink. If you right click on a report link in Cognos connection and select properties you will see the URL Cognos uses to open that report. If you look right after Cognos.cgi or cognosisapi.dll you will see a question mark, followed by a list of parameters and values. In a URL anything after the question mark is a querystring. The querystring looks something like this:
As you can see there are several values being passed in. 3 of the parameters are required, b_action=cognosViewer, ui.action=run(or view) and ui.object=[object search path] . There are several other options also available, including all of those mentioned earlier, which may all be based in via a URL. For a more comprehensive list and a detailed explanation of each parameter refer to the Cognos SDK User Guide chapter 17, which explains the user of URLs.
There are several ways this might be useful within your organization. You can use it for application integration and report automation. If you want a list of icons in your desktop for reports you run frequently, you can edit the URL and pass in different prompt values for each one. Here we will walk through a simple example of doing this by creating 2 reports and using one of them as a context sensitive detail report within the other.
Cognos allows you to create master detail sections within a report, essentially create a sub-report for each section. However because these are part of the same list, this means that you will be generating all of the detail sections for each parent. What if you only wanted to run it for the ones you choose? Using a little JavaScript you can create an IFrame, and through the URL pass the parent or master value to the child report. In the IFrame you would have a fully interactive report for just that section, run on-demand. Unlike the master-detail reports you can add things like additional prompts and drill-throughs to the detail report, and have it all run in the IFrame without ever rerunning the parent query.
Lets walk through an example of creating a simple interactive report in Report Studio. I will be using the Go Sales and Retailers sample package, but you can use any package, but you will have to modify one line in the scripts to point to the subreport in the new location. The same is true if you name the sub-report something other than Detail.
1. 2.
Start by creating a new Line Chart report. This report will serve as the sub-report. Set the chart values as follows:
o o o
Add Quantity as the default Measure Add Order Month to Categories (x-axis) Add Retailer Type to Series
3. 4. 5.
Add the following detail filter to the query for your chart [gosales_goretailers].[Products].[Product type] = ?prodtype? Because this will be a sub-report we only want the chart to show, remove the report header and footer. Change the chart dimensions so it will fit inside of the IFrame, set the height to 180px and the width to 480px. If your chart is larger or of different dimensions you may have to edit the script in the master report to change the size of the IFrame.
6.
Name the report Detail and save it to the Go Sales and Retailers and Retailers package. You may save the report anywhere you like and give it any name but you will have to modify the search path in the script accordingly.
7.
Now create the master report by creating a list report and adding the following columns:
o o o o o o o
Products.Product line Products.Product type Orders.Quantity Orders.Returned Quantity Order.Revenue Order.Planned Revenue A calculated column for % of Planned Revenue
Any number of columns will do. I added several to make the list wide enough for the sub-report.
8. 9.
Group the list by Product line then Product type. Create a Footer for Product type.
o o
From the Report Studio menu select Structure Headers & Footers List Headers & Footers Check the Product type (footer) option.
10. Unlock the report using the unlock button in the toolbar, this will allow us to work inside the footer cell instead of treating the whole footer as a single object. 11. Once the report is unlocked, remove the bolded <Product type> query item from inside of it. Before deleting make sure you highlight the query item only, not the whole footer.
12. Now add 3 HTMLItems to the footer 1. 2. 3. In the first one put the following <div><a href="#" onclick="showDetail()" productLine=" For the second one, change the Soure Type property from Test to Data Item Value, then select Product type as the data item. In the third one place the following ">Show Details</a></div>
At runtime it will concatenate the 3 HTML Items creating a link with the product line as a property. For example: <div><a href="#" onclick="showDetail()" productLine="Packs">Show Details</a></div>
Place a 4th HTML Item above the list and paste the following javascript into it. This is the script that will create and show or hide the sub-report when the link is clicked. This is also the script you will need to modify if you chose a different location, name or size for the sub-report.
<script language=javascript> function showDetail() { var link = event.srcElement; var sProductType = link.productLine; var cell = link.parentElement.parentElement; var iframe = (cell.getElementsByTagName("iframe").length > 0) ? (cell.getElementsByTagName("iframe")[0]) :(null); if(link.innerText == "Hide Details") { link.innerText = "Show Details"; if(iframe != null) { iframe.style.display="none"; } } else { link.innerText = "Hide Details"; if(iframe == null) { //Set up the IFrame iframe = document.createElement("iframe"); iframe.style.height="200px"; iframe.style.width="500px"; iframe.frameBorder="0"; iframe.scrolling="no"; //Create a URL var src = "http://rmvmsc84/cognos8/cgi-bin/cognosisapi.dll"; src += "?b_action=cognosViewer"; src += "&ui.action=run"; src += "&cv.toolbar=false"; src += "&cv.header=false"; src += "&ui.object=%2fcontent%2fpackage%5b%40name%3d%27GO%20Sales%20and%20Retailers%27%5d%2freport%5b%40na me%3d%27Detail%27%5d"; src += "&run.prompt=false";
src += "&p_prodtype="; src += escape(sProductType); //set the IFrame URL iframe.src = src; //Add the IFrame to the footer cell.appendChild(iframe); } iframe.style.display = ""; } } </script>
And when you run the report and click on one of the Show Detail links it should look something like this:
How to get more information Many of the values are documented in chapter 17 of the SDK User Guide. You can view the URL for the link in Cognos Connection as we did earlier, this will show you options that are being passed to that report. And of course, because this is a supported feature, you may also post questions to Cognos support, or search their knowledge base. But if you want to dig a little deeper here are a couple of tools that will help you to find out what Cognos is passing.
IE Developer Toolbar (http://www.microsoft.com) offers the ability to see all of the form values in a web page. Many times Cognos uses forms to pass information to the server through a POST. These values are usually store in hidden text boxes. This will allow you to see the form values to see what Cognos is passing to the server. Fiddler (http://www.fiddlertools.com) is a free tool for debugging web applications. When it is run it acts as a proxy, allowing you to view, and manipulate, all of the web traffic going in and out of your local computer. You can use this to intercept and record all of the calls the web page is making to the Cognos server, weather it is through a URL (GET) or a web form (POST).