Cognos SDK Guide by BI Centre can be purchased from PayPal.

You will have your own functional Cognos 8 SDK web solution that has been tailored to be scalable and flexible in order to adapt to your unique business requirements and solution architecture.


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);

            }
        }