Sometimes you just need two technologies to talk to each other. This article will describe how easy it is to make your Cognos reports call Active Server Pages and your Active Server Pages to call Cognos reports.
How to reference ASP objects in Cognos
This is really very easy. In Cognos Report Studio, drop an HTML Item into your report. Then add code to this HTML Item similar to the following:
<iframe
src =”/myaspdir/myaspcode.asp”
height=”100″
width=”100%”
align=”right”
frameborder=”0″
scrolling=”no”>
</iframe>
How to reference Cognos Reports with ASPs
In order to do this, you must make an HTTP reference to the Cognos API. This is similar to how Cognos Connection calls and interacts with Cognos Reports. The line of code you see in your web browser every time you run a Cognos report is such an API call.
The reason why these API calls always look incomprehensible is that they are often very long, and all special characters are translated into hexadecimal characters. All that our example API will do is call the Cognos API to run the report titled “My Report”.
The reference we need to run this report is simply this: /content/folder[@name='My Folder']/report[@name='My Report']
But it must be translated into hexidecimal characters to look like this: %2fcontent%2ffolder%5b%40name%3d%27My%20Folderd%27%5d%2freport%5b%40name%3d%27My%20Report%27%5d&
So our Cognos API call string will be made up of 3 or 4 parts:
Part 1: The API call “http://” & Your Server Id & “/bi84/cgi-bin/cognosisapi.dll”
Part 2: The API command “?b_action=xts.run&m=portal/report-viewer.xts&ui.action=run”
Part 3: The Cognos Report reference “ui.object= “%2fcontent%2ffolder%5b%40name%3d%27My%20Folderd%27%5d%2freport%5b%40name%3d%27My%20Report%27%5d&”
Part 4 (Optional): Any specific report parameters you want to include. Parameters are referred to by name, with a &p_ prefix attached. To assign MyParameter to 1, the string value would be “&p_MyParameter=1
With our string built, we are ready to make the API call. This can be done in the ASP code, like this:
mainFrame.Text = “<iframe style=’width:1000px; height:1000px;’ scrolling=’no’ frameborder=’0′ runat=’server’ src=’” & str_COGNOS_API_CALL & “‘ name=’bottom’ style=’padding:0px; margin:0px;’>”

#1 by Paul Finn on March 11, 2011 - 9:20 am
Hi,
Nice article, and one that can be easily applied to more than just ASP.
One question though: Is the src attribute of the IFRAME constrained by URL length limitation in some browsers?
Will this technique run into problems if there are many parameter/value combinations or particularly long ui.object references?
Thanks,
Paul
#2 by Scott Andrews on March 11, 2011 - 5:19 pm
That is a very good question. While I have not run into specific issues with the length of URL references for Cognos reports, I imagine that this could indeed pose problems. Microsoft Internet Explorer’s reported maximum URL length is 2083 charcters. Mind you, because this is a browser limitation, I suspect the same issues would impact your Cognos environment. Make sure to test your Cognos reports separately from the ASP pages in development so you can identify the source of such problems.
#3 by JPunk on July 26, 2012 - 2:23 pm
when I pass some special character in the URL report doesn’t show it. E.g. Order# 11112, I see only ‘Order; in the report. String after # is not visible in the report.
Do you have any clue about that?
#4 by Scott Andrews on July 26, 2012 - 3:09 pm
You want to be very careful with special characters in this situation – they can mean very specific things in code. # and % definitely fall into this category. Instead of passing Order# 11112, can you pass simply 11112? The simplier you make the parameter value the better.