.NET and Cognos Integration: Send Parameters to Cognos Report

Even though there are many resolutions online none of them are complete.

Here I want to explain briefly how to display the report in an IFRAME in ASP.NET, also how to pass the authentication parameters and finally how to pass report filter parameters.

For the first step to complete we just need any Cognos report URL that either accepts parameters or not. Because any Cognos report will accept an authentication parameter, but for passing additional filter parameters, we need a report URL that accepts parameters from .NET, in other words we need a report URL that is not precompiled and is saved as HTML or an offline report.

The Report URL will have all the special characters that needs to be replaced with the decoded symbols. Refer to here to find all the equivalent decoding characters.

Also, Cognos is always authenticated by AD credentials, so to complete the following example what is needed is an AD account that has access to Cognos reports and the reports should be public reports.

Display Cognos Report in IFRAMES and ASP.Net

HTML

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="IFrameExample.aspx.cs"  
  2.     Inherits="JnJ.OnLineForms.POC.IFrameExample" %>  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4. <html xmlns="http://www.w3.org/1999/xhtml">  
  5. <head id="Head1" runat="server">  
  6.     <title></title>  
  7.     <style type="text/css">  
  8.         .style1  
  9.         {  
  10.             width: 292px;  
  11.         }  
  12.         .style2  
  13.         {  
  14.             width: 362px;  
  15.         }  
  16.         .style3  
  17.         {  
  18.             width: 384px;  
  19.         }  
  20.     </style>  
  21. </head>  
  22. <body style="font-family: Verdana; font-size: 9pt">  
  23.     <form id="form1" runat="server">  
  24.     <table border="0">  
  25.         <tr style="width: 800px">  
  26.             <td colspan="3">  
  27.                 <iframe frameborder="1" style='width: 1141px; height: 321px;' runat="server" id="filterIFrame"  
  28.                     name="filterIFrame"></iframe>  
  29.             </td>  
  30.         </tr>  
  31.         <asp:Button ID="Submit" runat="server" Text="Submit" OnClick="GetReport" />  
  32.     </div>  
  33.     </form>  
  34. </body>  
  35. </html> 

CS file

  1. protected void GetReport(object sender, EventArgs e)  
  2. {  
  3.     Session["UserId"] = "ADUserID";  
  4.     Session["Pwd"] = "ADPassword";  
  5.     filterIFrame.Attributes["src"] = "http://10.10.100.100/ibmcognos/cgi-bin/cognos.cgi?b_action=cognosViewer&ui.action=run&ui.object=/content/folder[@name='User POC_DEMO']/folder[@name='POC']/folder[@name='XXX_POC_XXX']/folder[@name='Presentation_V1']/report[@name='POC Report Template']&ui.name=POC Report Template&run.outputFormat=&run.prompt=false  
  6. }  

 

In the preceding example, once you run the application, you need to enter the user ID and Password.

Passing Authentication Parameters

CS File

  1. protected void GetReport(object sender, EventArgs e)  
  2. {  
  3.     Session["UserId"] = "ADUserID";  
  4.     Session["Pwd"] = "ADPassword";  
  5.     filterIFrame.Attributes["src"] = "http://10.10.100.100/ibmcognos/cgi-bin/cognos.cgi?b_action=cognosViewer&ui.action=run&ui.object=/content/folder[@name='User POC_DEMO']/folder[@name='POC']/folder[@name='XXX_POC_XXX']/folder[@name='Presentation_V2']/report[@name='POC Report Template']&ui.name=POC Report Template&run.outputFormat=&run.prompt=false&CAMUsername=" + Session["UserId"] + "&CAMPassword=" + Session["Pwd"];  
  6. }  

In the code above, just see the appended "CAMUsername" and "CAMPassword" parameters as query string parameters, once you run the application at this step you will not be prompted for user id and password.

Passing additional filters

In this example let us see that we have an application where we can select parameters and those parameters needs to be passed to Cognos to filter the data.

CS file

  1. protected void GetReport(object sender, EventArgs e)  
  2. {  
  3.     Session["UserId"] = "ADUserID";  
  4.     Session["Pwd"] = "ADPassword";  
  5.     filterIFrame.Attributes["src"] = "http://10.10.100.100/ibmcognos/cgi-bin/cognos.cgi?b_action=cognosViewer&ui.action=run&ui.object=/content/folder[@name='User POC_DEMO']/folder[@name='POC']/folder[@name='XXX_POC_XXX']/folder[@name='Presentation_V3']/report[@name='POC Report Template']&ui.name=POC Report Template&run.outputFormat=&run.prompt=false&CAMUsername=" + Session["UserId"] + "&CAMPassword=" + Session["Pwd"] + "&p_Month=" + ddlMonth.SelectedValue.ToString() + "&p_Year=" + ddlYear.SelectedValue.ToString();  
  6. }  

In the preceding example notice that we have passed the additional parameters "p_Year" and "p_Month". Be careful at this step, sometimes the Cognos default picks up "P_Year" and "P_Month"; in this case you again need to prefix with "p_" to the parameters as in the following:

  1. protected void GetReport(object sender, EventArgs e)  
  2. {  
  3.     Session["UserId"] = "ADUserID";  
  4.     Session["Pwd"] = "ADPassword";  
  5.     filterIFrame.Attributes["src"] = "http://10.10.100.100/ibmcognos/cgi-bin/cognos.cgi?b_action=cognosViewer&ui.action=run&ui.object=/content/folder[@name='User POC_DEMO']/folder[@name='POC']/folde[@name='XXX_POC_XXX']/folder[@name='Presentation_V3']/report[@name='POC Report Template']&ui.name=POC Report Template&run.outputFormat=&run.prompt=false&CAMUsername=" + Session["UserId"] + "&CAMPassword=" + Session["Pwd"] + "&p_P_Month=" + ddlMonth.SelectedValue.ToString() + "&p_P_Year=" + ddlYear.SelectedValue.ToString();  
  6. }  


Similar Articles