Buy the Cognos SDK Guide by BI Centre Now

The Cognos SDK Guide by BI Centre provides you with the complete source code for a C# web solution, C8.1 report based on the GOSR package, and a Word document that will serve as your core reference to understanding the Cognos 8 SDK. It will cover C8 SDK topics such as: authentication; querying the Cognos content store; rendering a C8 report in ASP.NET; exception handling; and much more.



Buy the Cognos 8 Modification Check Now







Monday, November 24, 2008

SDK - SSO for Series 7 gateway namespace using CSharp

using System;
using System.Collections;
using System.Web.Services;
using cognosdotnet_2_0;


namespace SetCredential
{

///
/// Summary description for Class1.
///

class SetCredential
{
private cognosdotnet_2_0.CognosReportNetBinding oCrn = null;

propEnum [] props = {propEnum.defaultName, propEnum.searchPath};

public SetCredential(string endPoint)
{
oCrn = new CognosReportNetBinding();
oCrn.Url = endPoint;
oCrn.Credentials= System.Net.CredentialCache.DefaultCredentials;
}


//
// get a list of the packages for the logged in user
//
public void getPackageList()
{
try
{
baseClass [] objInMyFolders = oCrn.query("//package",
props, new sort[]{}, new queryOptions());

int temp = 1; // If you've made it to here, SSO is working. Examine objInMyFolders to see the packages
}
catch (Exception e)
{
Console.Write("\n" +e.GetBaseException());

}
}

///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
String endPoint = "http://localhost/c84GA/cgi-bin/cognos.cgi";
SetCredential packageList = new SetCredential(endPoint);
packageList.getPackageList();
}
}
}

SDK - Bad version number in .class file

http://bicentre.blogspot.com/2008/11/sdk-bad-version-number-in-class-file.html

Monday, June 2, 2008

Access Manager LDAP -- add new user

Authenticator2.Application _AuthApp = new Authenticator2.Application(); Authenticator2.Document _AuthDoc; Authenticator2.DSConfigurations objDSConfigs; Authenticator2.Configuration objConfig; objDSConfigs = ((Authenticator2.DSConfigurations)_AuthApp.DSConfigurations); objConfig = ((Authenticator2.Configuration)objDSConfigs.Add("cognosserver",389,"dc=dev",0)); objConfig.DefaultSecuritySource = true; _AuthDoc = ((Authenticator2.Document)((Authenticator2.AuthenticatorDocuments)_AuthApp.Documents).OpenWithBasicSignon("default","administrator","mypassword","Root User Class")); Authenticator2.User objUser; objUser = ((Authenticator2.User)((Authenticator2.Users)((Authenticator2.Folder)_AuthDoc.UserFolder).Users).Add("MyNewUser")); //clean up System.Runtime.InteropServices.Marshal.ReleaseComObject(_AuthDoc); System.Runtime.InteropServices.Marshal.ReleaseComObject(_AuthApp);

Monday, May 12, 2008

New C8 SDK Utility --- Cognos 8 Modification Check

The BI Centre C8 Modification Check provides a Cognos SDK developer with a workable C# solution that will allow you to:

· Search the Content Store for items that have been modified after a selected date value

For example, if you were looking for all reports that were modified on June 3rd, 2008 then you would select the date June 2nd, 2008. The code will search for all items that have been modified after the selected date value from the date control.

The results of the search are then rendered to a text box control.






Friday, May 2, 2008

next Cognos SDK utility

We are currently working on a Cognos SDK utility that will return query a namespace to return all of the groups, users and their assigned privileges. The results will be added to .txt file.

Email us today if you would like to be notified when this utility has been completed.

Saturday, April 12, 2008

Cognos 8 SDK -- ContentManagerService passing authentication

If the logon was successful, the ContentManagerService becomes an authenticated service and a string known as a CAM Passport will be sent back to the SDK application in the BiBusHeader. When an SDK application creates an object to represent a Cognos 8 service, that object will contain a property called BIBusHeader. The BIBusHeader represents the SOAP header that is used to communicate with the Cognos 8 server. Within the BIBusHeader, is a property named CAM which in turn contains a property named CAMPassport. The CAM Passport returned by the logon() method is stored in the
CAMPassport property.

In an SDK application, the CAM Passport does not automatically propagate to other services that might be used within the application. Since the ContentManagerService is the only service than can logon and logoff, there needs to be ability to assign the CAM Passport to other services that the SDK application might require (such as the ReportService). This assignment is done simply by copying the BIBusHeader of the ContentManagerService to the BIBusHeader of the other service, thereby making that service an authenticated service.

Cognos 8 SDK -- Logging on

Unless Anonymous access is allowed, when a Cognos 8 SDK application is connected to the Cognos 8 server the application has no implied rights or access permissions. The Cognos 8 SDK application needs to login just as a general user would login to the Cognos portal.

If anonymous access is allowed, the Cognos 8 SDK application will be granted the same rights and permissions as the Anonymous user from the Cognos namespace. If anonymous access is not allowed and a Cognos 8 SDK application does not login, an exception will occur when the SDK application tries to perform an action such as querying the content store or running a report.

All logons and logoffs are performed through the ContentManagerService using the logon() and logoff() methods. None of the other Cognos 8 services can perform a logon or logoff operation.

Sunday, March 2, 2008

Cognos 8 SDK -- example of capturing reporting history

private boolean reportJobStatus()
{
boolean blnError = false;
Vector reportHistories = getReportHistories();
String reportName = "";

PropEnum props[] = new PropEnum[]{PropEnum.searchPath, PropEnum.defaultName, PropEnum.detail, PropEnum.detailTime, PropEnum.severity};
Sort sort = new Sort();
sort.setOrder(OrderEnum.ascending);
sort.setPropName(PropEnum.defaultName);
Sort[] sortOrder = new Sort[]{sort};

try
{
if(reportHistories.size() > 0)
{
for(int i =0; i < reportsearchpath =" (String)reportHistories.get(i) + "//historyDetail";
reportName = getReportName(reportSearchPath);
BaseClass bc[] = cmService.query(new SearchPathMultipleObject(reportSearchPath ), props, sortOrder, new QueryOptions());
if(bc != null && bc.length > 0)
{
for(int j =0; j < historydetail =" (HistoryDetail)bc[j];" blnerror =" true;">" + reportName + "" +
" " + historyDetail.getDetailTime().getValue().getTime() + "" +
" " + historyDetail.getDetail().getValue() + "";
}
}

}
}
}
}
catch(Exception e)
{ System.out.println("RunJobNowAndCaptureError::reportJobStatus()");
e.printStackTrace();
}
return blnError;
}

Monday, February 25, 2008

Cognos SDK -- cube drill down

Here is a C# Cognos SDK code snippet that shows the ability to drill down into a cube report by using the Cognos SDK.  Take note of the bolded code lines below.  You will need to use the Report Service's .drill method and pass in values for the drillOptionParameterValues property.
 
simpleParmValueItem item = new simpleParmValueItem();
                item.use = "[great_outdoors_company].[Years].[Years].[Year]->:[PC].[@MEMBER].[20050101-20051231]";
                item.inclusive = true;
 
option[] drillOptions = new option[1];
                drillOptionParameterValues d1 = new drillOptionParameterValues();
                d1.name = drillOptionEnum.down;
                d1.value = parameters;
                drillOptions[0] = d1;
 
response = this.rptService.drill(response.primaryRequest, parameters, drillOptions);
 
 
 
 
private void GoToDrillDown(reportService1 rptService)
        {
            if (this.rptService == null)
            {
                this.rptService = rptService;
            }
            String reportPath = "/content/package[@name='Great Outdoors Company']/report[@name='MyTestReport']";
           String savePath = "c:\\temp";
            parameterValue[] parameters = new parameterValue[1];
            asynchReply response;
            searchPathSingleObject reportPathObj = new searchPathSingleObject();
            reportPathObj.Value = reportPath;
            try
            {
                option[] runOptions = new option[6];

                runOptionBoolean saveOutput = new runOptionBoolean();
                saveOutput.name = runOptionEnum.saveOutput;
                saveOutput.value = false;
                runOptions[0] = saveOutput;

                // Specify the output format.
                runOptionStringArray outputFormat = new runOptionStringArray();
                outputFormat.name = runOptionEnum.outputFormat;
                outputFormat.value = new String[] { "HTML" };
                runOptions[1] = outputFormat;

                //Set the report not to prompt as we pass the parameters if any
                runOptionBoolean rop = new runOptionBoolean();
                rop.name = runOptionEnum.prompt;
                rop.value = false;
                runOptions[2] = rop;

                runOptionInt maxRows = new runOptionInt();
                maxRows.name = runOptionEnum.verticalElements;
                maxRows.value = 20;
                runOptions[3] = maxRows;

                option[] drillOptions = new option[1];
                drillOptionParameterValues d1 = new drillOptionParameterValues();
                d1.name = drillOptionEnum.down;
                d1.value = parameters;
                drillOptions[0] = d1;

                //Set the option to always have the primaryRequest in the response
                asynchOptionBoolean includePrimaryRequest = new asynchOptionBoolean();

                includePrimaryRequest.name = asynchOptionEnum.alwaysIncludePrimaryRequest;
                includePrimaryRequest.value = true;
                runOptions[4] = includePrimaryRequest;

                runOptionLanguageArray roOutputFormat = new runOptionLanguageArray();
                roOutputFormat.name = runOptionEnum.outputLocale;
                String[] fmt = { "en-us" };
                roOutputFormat.value = fmt;
                runOptions[5] = roOutputFormat;

                //Run the report
                response = this.rptService.run(reportPathObj, new parameterValue[] { }, runOptions);
                //If response is not immediately complete, call wait until complete
                if (!(response.status == (asynchReplyStatusEnum.complete)))
                {
                    while (!(response.status == asynchReplyStatusEnum.complete))
                    {
                        //before calling wait, double check that it is okay
                        if (hasSecondaryRequest(response, "wait"))
                        {
                            response =
                             this.rptService.wait(
                               response.primaryRequest,
                               new parameterValue[] { },
                               new option[] { });
                        }
                        else
                        {
                            Console.Write("Error: Wait method not available as expected.");
                            return;
                        }
                    }
                    //check if output is ready

                    if (outputIsReady(response))
                    {
                        response =
                         this.rptService.getOutput(response.primaryRequest, new parameterValue[] { },
                          new option[] { });
                    }
                    else
                    {
                        Console.Write("output is not ready!");
                    }
                }

                String data = getOutputPage(response);
                // Write the report output to file system
                Console.Write("Writing the output of the original report..");


                StreamWriter sw = File.CreateText(savePath + "\\original.html");
                sw.Write(data);
                sw.Flush();
                sw.Close();


                //Drill down in the report
                //set up drill down parameter.
                simpleParmValueItem item = new simpleParmValueItem();
                item.use = "[great_outdoors_company].[Years].[Years].[Year]->:[PC].[@MEMBER].[20050101-20051231]";
                item.inclusive = true;

                parmValueItem[] pvi = new parmValueItem[1];
                pvi[0] = item;

                parameters[0] = new parameterValue();
                parameters[0].name = "Year";
                parameters[0].value = pvi;

                response = this.rptService.drill(response.primaryRequest, parameters, drillOptions);

                if (!(response.status == (asynchReplyStatusEnum.complete)))
                {
                    while (!(response.status == asynchReplyStatusEnum.complete))
                    {
                        //before calling wait, double check that it is okay
                        if (hasSecondaryRequest(response, "wait"))
                        {
                            response =
                             this.rptService.wait(
                               response.primaryRequest,
                               new parameterValue[] { },
                               new option[] { });
                        }
                        else
                        {
                            Console.Write("Error: Wait method not available as expected.");
                            return;
                        }
                    }
                    //check if output is ready

                    if (outputIsReady(response))
                    {
                        response =
                         this.rptService.getOutput(response.primaryRequest, new parameterValue[] { },
                          new option[] { });
                    }
                    else
                    {
                        Console.Write("output is not ready!");
                    }
                }

                data = getOutputPage(response);
                // Write the report output to file system
                Console.Write("Writing the output of the drill down report..");


                StreamWriter sw2 = File.CreateText(savePath + "\\drilldown.html");
                sw2.Write(data);
                sw2.Flush();
                sw2.Close();


                // release the conversation to free resources.
                this.rptService.release(response.primaryRequest);

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message.ToString());
                Console.WriteLine(ex.StackTrace);

            }
        }

Tuesday, February 19, 2008

Cognos 8 SDK -- prompt page with optional parameters

If you need to execute a Report Studio report that has optional parameters defined on the prompt page then you should code your Cognos SDK application to pass an empty parameter instead of an empty string.


// parameter values
ParmValueItem pvi[] = new ParmValueItem[1];

// If you pass an empty string to an optional parameter
// it will assume that you want to match an empty string in
// the filter. To get the desired behaviour, pass an empty
// parameter value
if (!inputValue.equalsIgnoreCase("")) pvi[0] = item1;

// Assign the values to the parameter.
params[i] = new ParameterValue();
params[i].setName(prm[i].getName());
params[i].setValue(pvi);

Thursday, February 14, 2008

display the contents of a folder in the Public Folder using C# and SDK

Here is the content store request in order to find all of the reports that exist under a specified folder.

baseClass[] bc = crn.query( "/content/folder[@name='ABCDEFG']//report", props, s, qo );

Tuesday, February 12, 2008

Cognos SDK Guide by BI Centre Sample?

Hello, did you want to have a quick preview of the guide before purchasing? If so then send us an email requesting your free sample of the guide today.

Saturday, February 2, 2008

Output.aspx.cs -- Displaying the report results

Now that the end user is able to interact with the report’s prompt page we need to execute the report and display the report values to our Output.aspx page. The Output.aspx.cs logic will contain a reference to the CognosSDK.cs function named resolvePrompts(). This function is used to determine the prompt type and prompt value that was executed on the report’s prompt page. These parameter values are then used to satisfy the parameter value collection that is passed in to the executeReport().


try
{
_frmData = Request.Form;
_selectedPkg = _frmData.GetValues("hidPkgName").GetValue(0).ToString();
_selectedRpt = _frmData.GetValues("hidRptName").GetValue(0).ToString();
_path = "/content/package[@name='" + _selectedPkg + "']/report[@name='" + _selectedRpt + "']";

asynchDetail[] _paramDetail = _cogSDK.GetParams(_selectedPkg,_selectedRpt,_rptService);
asynchDetailParameters _params = (asynchDetailParameters)_paramDetail[0];
int _pCount =_params.parameters.Length;

parameterValue[] _pv = _cogSDK.resolvePrompts(_frmData, _pCount);
string[] reportFormat = {"HTML"};

strHTML = _cogSDK.executeReport(_path, _pv, _rptService, reportFormat, false);
Response.Write(strHTML);
}

catch(Exception ex)
{
_ErrMsg = ex.Message.ToString();
Response.Write(_ErrMsg);
}

return;



We have already seen that the executeReport() will return a string variable value of the report’s output. This is achieved by applying an asynchReply variable to the Report Service’s .run() method.

try
{
spSingle.Value = reportSearchPath;
asynchReply C8reply = reportService.run(spSingle, pv ,arrRunOpts);

if (C8reply != null)
{
strHTML = getOutputPage(C8reply);

return strHTML;
}

else
{
return null;
}

}
catch (SoapException exSoap)
{
ExHandler exCognos = new ExHandler(exSoap);
return _ErrMsg = exCognos.Details + " :-: " + exCognos.Message + " :-: " + exCognos.Severity + " :-: " + exCognos.ErrorCode;
}
catch (Exception ex)
{
return _ErrMsg = ex.Message.ToString();
}


Output.aspx.cs will finally pass this string value to the page’s Reponse.Write() and render the dataset to the end user.

Thursday, January 24, 2008

Run a report with prompts -- CognosSDK.cs

Our working sample includes Report Studio reports that all contain prompts. In order for the reports to be executed they need to have their prompt page parameter objects populated with a valid parameter value. In order to achieve this we need to display the report's prompt page to the end user so that they can enter the prompt value into the appropriate prompt control. The approach that we will use to render the report's prompt page to the end user is to execute the selected report and satisfy the method's signature with an empty parameter value collection. Passing in an empty parameter value collection forces the Report Service to place the request into a 'prompting' status. We can then retrieve the request's HTML representation of the report's prompt page, and then render this HTML string to the ASP.NET page.



Note that our executeReport() method is looking for a Boolean value to state whether or not to prompt. When we want the prompt page then we set this Boolean value to True.



public string executeReport(string reportSearchPath,parameterValue[] pv, reportService1 reportService, string[] strFormat, bool blnPrompt){



………… method body………

…………

…………

}





The executeReport() method contains an asynchReply variable that is used to capture the conversation context of the request.



asynchReply C8reply = reportService.run(spSingle, pv ,arrRunOpts);





We will then pass the C8reply variable as an input parameter to the getOutputPage() method. This method will be used to populate a string variable with a string representation of the prompt page's HTML. It is this value that is written to PromptPage.aspx and displays the report's prompt page to the end user.



strHTML = getOutputPage(C8reply);





public string getOutputPage(asynchReply response)

{

asynchDetailReportOutput reportOutput = null;



try

{

for (int i = 0; i < response.details.Length; i++)

{

if (response.details[i] is asynchDetailReportOutput)

{

reportOutput =

(asynchDetailReportOutput)response.details[i];

break;

}

}

}

catch (SoapException exSoap)

{

ExHandler exCognos = new ExHandler(exSoap);

return _ErrMsg = exCognos.Details + " :-: " + exCognos.Message + " :-: " + exCognos.Severity + " :-: " + exCognos.ErrorCode;

}



//text based output is split into pages -- return the current page

return reportOutput.outputPages[0].ToString();

}



Before we display the prompt page to the end user we want make some modifications to the HTML that was returned. Our CustomizeHTML() helper function is used to update the HTML in order to work with our sample web solution. The main change will involve adding our own customized finish button to the prompt page to control the form's submission to Output.aspx. This will also enable us to add our own JavaScript function to the button's onClick() event. This is achieved in the CognosSDKHelper.js file.

Monday, January 21, 2008

Show reports for a package in Reports.aspx -- CognosSDK.cs

When you query the Cognos Content Store it is important to remember that you can search for one specific item, or you can search for all objects of a specified type. For example, if you wanted to find the details for one particular report item then you would use the following syntax for your search path value.



spSingle.Value = "/content/package[@name='" + _pkgName + "']/report[@name='" + _rptName + "']";





However, if you wanted to find all reports for a specified package then you would use the following syntax for your search path value.



_reportPath = "/content/package[@name='" + _package + "']/report//*";





This is the same logic if you wanted to find all packages that exist in the Cognos Content Store.



_packagePath = "/content//package/*";

Thursday, January 17, 2008

Show All Packages in Default.aspx -- CognosSDK.cs

Show all packages

 

The entry point to our Cognos SDK web solution will be Default.aspx.  This will be a basic web page that will only contain a listbox control and a command button.  The listbox will be populated with all of the package items that exist in the specified Cognos Content Store.

 

Default.aspx will call the CognosSDK.cs object in order to query the Cognos Content Store for a list of Content Store objects.  In this case, we will only be interested in retrieving the list of all Content Store package objects that are of the type packageConfiguration.

 

The Default.aspx.cs PageLoad() event will contain the following C# code.

 

if (!Page.IsPostBack)

                  {

                       

                        baseClass[] _bc =  _cogSDK.getObjects(_cmService, _CSTypePkg, null);

                 

                        if (_bc != null)

                        {

                              for(int i=0; i<_bc.Length; i++)

                              {

                                    if ( _bc[i] is packageConfiguration)

                                    {                            

                                          lstPackages.Items.Add(_bc[i].defaultName.value.ToString());                        

                                    }

                              }    

                        }

                  }

 

 

 

This will require the CognosSDK.cs object to be instantiated in order to access the getObjects() method.

 

public baseClass[] getObjects(contentManagerService1 _cmService, string _path, string _package)

 

Monday, January 14, 2008

Cognos SDK Guide by BI Centre -- web.config

Here is a concise definition for a web.config file from wikipedia.

Source:  wikipedia

“The web.config is the main settings and configuration file for an ASP.NET web application. The file is a text based XML document that defines such things as connection strings to any databases the application uses, the default language for child pages, whether debugging is allowed and how it can be implemented, whether session state is used by default, what type of authentication is used, if any, and so on.

Web.config files can only be placed inside directories that have been configured as ASP.NET applications, commonly the web application's root directory. Web.config files inherit properties from higher level .config files and ultimately machine.config however some settings inside machine.config cannot be overridden.

The web.config file is so central to the ASP.NET framework that when the file is saved, IIS restarts the application it belongs to. Visual Studio will automatically create a web.config file when needed, such as compiling a web application to run in debug mode.”

Our web application will be mainly using the web.config for storing the default login credentials for an Administrator user, the dispatcher value and the includes folder for any JavaScript or images.

 

<appSettings>

      <add key="CTSpwd" value="admin1234" />

      <add key="CTSuid" value="administrator" />

      <add key="CNmspace" value="1101" />

      <add key="CCurl" value="http://server/cognos8/cgi-bin/cognosisapi.dll?b_action=xts.run&amp;m=portal/cc.xts&amp;CAMUsername=CC_UID&amp;CAMPassword=CC_PWD&amp;h_CAM_action=logonAs&amp;CAMNamespace=CC_NM" />

      <add key="CognosSDKPathIncludes" value="http://server/cognos8/" />

      <add key="CognosDispatcher" value= "http://server:9300/p2pd/servlet/dispatch" />

      <add key="CSTypePkg" value="packageConfiguration" />

      <add key="CSTypeRpt" value="report" />

</appSettings>

 

 

The C# code uses the following syntax to retrieve the value stored in the web.config.

 

_dispC8 = ConfigurationSettings.AppSettings["CognosDispatcher"];

 

You can see that this value corresponds to the web.config setting.

 

<add key="CognosDispatcher" value= "http://MyServerName:9300/p2pd/servlet/dispatch" />

 

 

Friday, January 11, 2008

Exception Handler Class -- Exhandler.cs

ExHandler.cs is used to handle SOAP Exceptions that may be encountered when making Cognos service requests.  The ExHandler.cs class allows you to display a meaningful error message to the end user.  It captures the severity, error code, message and details of the exception that has been encountered.  These values are appended and returned as a string.

 

This is example code to capture the Exception’s severity.

 

/// Return the exception severity. ///

public string Severity{

      get{

            XmlNode severityNode = exSoap.Detail.SelectSingleNode( "//severity");

                  if (severityNode != null)

                  {

                        return severityNode.InnerText;

                  }

                       

return "";

                 

}

}

 

 

 

Your web solution should have all of it’s TRY-CATCH statements updated in order to reference the functionality ExHandler.cs class file.  You would simply have to instantiate the object in your updated Catch statements.

 

ExHandler exCognos = new ExHandler(exSoap);

 

 

Here is a more detailed example showing the updated Catch statement and appending a string object with the full exception message.

 

try

                  {

                        _cmService = new contentManagerService1();

                        _rptService = new reportService1();

 

                        _dispC8 = ConfigurationSettings.AppSettings["CognosDispatcher"];

                        _NmSpace = ConfigurationSettings.AppSettings["CNmspace"];

                        _Pwd = ConfigurationSettings.AppSettings["CTSpwd"];

                        _Uid = ConfigurationSettings.AppSettings["CTSuid"];

                        _CSTypePkg = ConfigurationSettings.AppSettings["CSTypePkg"];

                        _CSTypeRpt = ConfigurationSettings.AppSettings["CSTypeRpt"];

 

                        _cmService.Url = _dispC8;

                        _rptService.Url = _dispC8;

 

                        _cogSDK = new CognosSDK();

 

                        _cogSDK.CognosLogon(_cmService,_NmSpace,_Uid, _Pwd);

                        _rptService.biBusHeaderValue = _cmService.biBusHeaderValue;

                  }

 

                  catch (SoapException exSoap)

                  {

                        ExHandler exCognos = new ExHandler(exSoap);

                        _ErrMsg = exCognos.Details + " :-: " + exCognos.Message +  " :-: " + exCognos.Severity +  " :-: " + exCognos.ErrorCode;

                  }

                  catch (Exception ex)

                  {

                        _ErrMsg = ex.Message.ToString();

                  }    

 

 


 

 

Thursday, January 10, 2008

CognosSDK.cs -- Helper Functions

Your Cognos SDK class will also contain several helper functions that will aid you in querying and executing against the Cognos 8 Content Store.  One example is the sample code to resolve a report’s prompt page prompts and pass the final parameter collection a Report Service’s .run method.  The purpose of the method is to iterate through the prompt page’s form collection and identify all Cognos 8 prompt controls by name and retrieve their associated value.  This method requires that your Cognos 8 Report Author follows a standardized naming convention for the Report Studio prompt pages.  For example, our sample Report Studio reports will name all of the prompt page prompts in the following manner.

 

v      Date Time prompts – p_dteStartDate

v      Value prompt – p_txtFirstName

v      Multiple Select prompt – p_lstCity

 

NOTE:  As you progress through the code in the CognosSDK.cs file you will find references to string functions that rely on this naming convention.  You may be forced to alter your CognosSDK.cs code to work with your Cognos 8 Report Studio naming standards.

 

For example:

 

_promptType = nvcFormData.Keys[x];             

int _posPrompt = _promptType.LastIndexOf("p_");

                 

if (_posPrompt == 2)

{

      _promptName = _promptType.Substring(2, _promptType.Length - 2);

      _promptType = _promptType.Substring(_posPrompt + 2,3);

}

Monday, January 7, 2008

CognosSDK.cs -- Request Report Parameters

A Cognos Report Studio developer can design a report to apply specific filtering on a data item. For example, if a report developer wanted to only return all sale orders that occurred in the city of London then they could design a prompt page that allowed a user to select London as the city parameter item. The sales order query would be filtered based on the selected parameter value.

Knowing the parameters that exist in the report definition is a vital piece of information when executing Cognos Report Studio reports via the Cognos SDK. If the parameter collection is not satisfied then the report will maintain a state of prompting.

Here is a code example that shows the request for a report’s parameter collection. You should not that the report item is an input parameter contained in the search path for the report.

public asynchDetail[] GetParams(string packageName, string reportName, reportService1 rptService)
{
try
{
searchPathSingleObject spSingle = new searchPathSingleObject();
string _pkgName = packageName;
string _rptName = reportName;

spSingle.Value = "/content/package[@name='" + _pkgName + "']/report[@name='" + _rptName + "']";


asynchReply _resParameters = rptService.getParameters(spSingle, new parameterValue[]{},new option[]{});

asynchDetail[] _details = _resParameters.details;

return _details;
}

catch (Exception ex)
{
_ErrMsg = ex.Message.ToString();
return null;
}
}


Now that you have asynchDetail[] object you can access the report’s parameter collection information.

Thursday, January 3, 2008

CognosSDK.cs -- Request Content Store Objects

The Cognos Content Store contains the metadata representation of items such as reports, query items, report views, and security settings. The Cognos SDK code can call the Content Manager’s .query() method to search for and retrieve Content Store items. The getObjects() method is an example of searching the Content Store and finding either all Content Store package items or all report items for a specified package.

public baseClass[] getObjects(contentManagerService1 _cmService, string _path, string _package)

{
propEnum[] _props = new propEnum[]{propEnum.searchPath,propEnum.defaultName,propEnum.objectClass, propEnum.modificationTime, propEnum.connectionString, propEnum.creationTime, propEnum.link, propEnum.specification, propEnum.version, propEnum.defaultName, propEnum.portalPages, propEnum.ancestors, propEnum.owner};



if(_cmService != null)

{

sort[] _sort = {new sort()};

_sort[0].order=orderEnum.ascending;

_sort[0].propName=propEnum.defaultName;



_packagePath = "/content//package/*";

_reportPath = "/content/package[@name='" + _package + "']/report//*";



searchPathMultipleObject _spMulti = new searchPathMultipleObject();



if (_path == "packageConfiguration")

{

_path = _packagePath;

}

else if (_path == "report")

{

_path = _reportPath;

}

else

{

_path = null;

}



_spMulti.Value = _path;



try

{

//Query Cognos 8 and return the Base Class Array to the calling method

baseClass[] _bc = _cmService.query(_spMulti, _props, _sort, new queryOptions());

if(_bc != null)

{

//if the search request returned results

if(_bc.Length > 0)

{

return _bc;

}

else

{

return null;

}

}

}





catch(Exception ex)

{

_ErrMsg = ex.Message.ToString();

return null;

}

}



//no results found

return(null);

}

Cognos 8 SDK google search

Google

New C8 SDK Utility --- Cognos 8 Modification Check

The BI Centre C8 Modification Check provides a Cognos SDK developer with a workable C# solution that will allow you to:

· Search the Content Store for items that have been modified after a selected date value

For example, if you were looking for all reports that were modified on June 3rd, 2008 then you would select the date June 2nd, 2008. The code will search for all items that have been modified after the selected date value from the date control.

The results of the search are then rendered to a text box control.