Wednesday, October 19, 2011

Cognos Executed Report's Report view finally on the <iframe>


The requirement was to view the executed report to the user using the cognos viewer inside an iframe which is already in an application (which is totally outside the cognos application domain). Imagine the below report view is loaded to the iframe through the cognos viewer in a SaaS application.

 
Sounds simple right? Yes it is, but it was not that easy to implement even though the executed reports view is already available. To implement this simple requirement with an additional syntax, it took couple of hours due to insufficient information. However there were few sources  which has a quite similar approach but there where some drawbacks experienced when applying them. In each approach no one has indicated such implementation to view the executed report using cognosLaunch SDK js method, so I believed it is good to share this with the community.

Without just adding the simple syntax necessary for the above requirement, I would also like to provide some additional details that can be helpful for another audience.

SDK includes a JavaScript method (cognosLaunch method) that is useful for executing reports with multiple parameters.

Can we run a report directly through the cognosLaunch, js method?

  • Yes, report can be directly run through the cognosLaunch js method with multiple parameters (in terms of cognos, multiple prompts) but some browsers have limitations in the HTML request URL length.
  • Therefore, if there is a high probability in request URL exceeding the browser limitation, this method can be a failure.
  • In order to avoid the issue of request URL, can use of report prompts to get the necessary parameter values. Since avoiding report prompts is a requirement so we cant make use of report prompts


Why do we need to execute report and have a report view?

There is a requirement, once user select parameters and execute the report, results should exist as long as user wishes and user should be able to view the executed report instantly.
(If user runs the report through the cognosLaunch, report will be executed and can be viewed each time the user runs the report, but output will not be saved.)

This will cause two more issues,
  1. First issue will be the execution time, when data capacity is much bigger, the execution time will be considerably high. Then user will not be able to get the report instantly.
  2. Next issue will be when executing the report in a different time, might give conflicting results based on updated data set for the selected parameters. (if data set has changed)

When considering above matters and requirements now its obvious that reports needs to be executed once  and report outputs need to be saved as report views. Finally recall them using cognosLaunch js method. The bellow image will provide a high level picture of the scenario.





How to make a report to run and create a report view using Cognos SDK ?

We need to specify the report to run, the spec path of the new location for the report output and the name of the new report view.

The following are the simple steps need to follow to in order to create a new report view using the cognos SDK

  1. Connect to Cognos service.
  2. Assign appropriate values as run options.
  3. Execute the SDK run method


package chamantha.blog.cognos.sdk.development;
 
//NOTE : does not exists all the import statements
//high level indication of imports
import com.cognos.developer.schemas.bibus.*;
 
public class CognosReportExecution {
 
    /**
     * Execute the report using the Cognos SDK and
     * returns the report view spec path
     */
    public String executeReport() throws Exception {
 
    try {
        String reportSpecPath =
        "/content/folder[@name='Report Folder']/report[@name='My Report']";
 
        // Initiate the Cognos connection
        //This will be utility class that will help user to connect to -
        // -cognos using that is utilizing again cognos SDK
        CognosUtil cognos = new CognosUtil();
 
        // get Cognos SDK report service
        ReportService_PortType reportServicePortType =
               cognos.getreportServicePortType();
 
        // Initiate cognos search path for given report spec path
        SearchPathSingleObject searchPathSingleObj = new SearchPathSingleObject();
        searchPathSingleObj.set_value(reportSpecPath);
 
 
        ParameterValue[] paramValues = new ParameterValue[1];
        paramValues[0] = new ParameterValue();
 
        paramValues[0].setName("ForcastingYear");
        String year = "2011";
        SimpleParmValueItem valueItem = new SimpleParmValueItem();
        valueItem.setUse(year);
        valueItem.setDisplay(year);
        valueItem.setInclusive(true);
 
        ParmValueItem parmValueItems[] = new ParmValueItem[1];
        parmValueItems[0] = valueItem;
 
        paramValues[0].setValue(parmValueItems);
 
 
        // Speficify neccesary cognos SDK options
        Option[] options = new Option[3];
 
        // Indicate the prompt avaiability
        RunOptionBoolean promptAcceptence = new RunOptionBoolean();
        promptAcceptence.setName(RunOptionEnum.prompt);
        promptAcceptence.setValue(false);
        options[0] = promptAcceptence;
 
        // Format of the out put this can be multiple output formats too
        RunOptionStringArray runOptionsFormats = new RunOptionStringArray();
        runOptionsFormats.setName(RunOptionEnum.outputFormat);
        runOptionsFormats.setValue(new String[]{"HTML"});
        options[1] = runOptionsFormats;
 
 
        // Set Report view  name and the Locale
        MultilingualToken[] multilingualToken = new MultilingualToken[2];
        multilingualToken[0] = new MultilingualToken();
        multilingualToken[0].setLocale("en-us");
        multilingualToken[0].setValue(newReportName);
 
        // Where and how new report will be saved
        RunOptionSaveAs runOptSaveAs = new RunOptionSaveAs();
        runOptSaveAs.setName(RunOptionEnum.saveAs);
        runOptSaveAs.setObjectClass(ReportSaveAsEnum.reportView);
        runOptSaveAs.setObjectName(multilingualToken);
        runOptSaveAs.setParentSearchPath(newPathToSaveReportView);
 
        options[2] = runOptSaveAs;
 
 
        AsynchReply asynchReply =
        reportServicePortType.run(searchPathSingleObj,paramValues, options);
 
        AsynchDetail[] asynchDetails = asynchReply.getDetails();
 
        // A utility method to get the report spec path from asynchDetails
        String reportViewSpecPath = getReportViewSpecPath(asynchDetails);
 
        return reportViewSpecPath;
 
        } catch (Exception exception) {
            // Log the error and throw expected exception
            throw new Exception();
        }
    }
    /*
     * more methods providing utility.
     */
}




The above code snippet will return report spec path which is similar to bellow

/content/folder[@name='ReportView']/reportView[@name='Report view Name']

How to launch the report in an iframe using the cognosLaunch js method provided by the cognos SDK ?

The cognos launch method will take the parameters as shown bellow, which is mandatory to get the report view



What was the missing syntax ?

Specifying the report view spec path like “defaultOutput( REPORT_VIEW_SPEC_PATH )” is the missing syntax or the mechanism which was not known. This syntax was needed to run the report view which already saved in the cognos CMS. This was only able to identify by analyzing the default URL in the cognos IDE. The below image will show how I have identified syntax.


Then again what above simple syntax actually accessing the default, report version which is created for the respective report view.

2 comments:

  1. Nicely explained and all the best with your researches. Hope to see more such useful articles.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete