Monday, April 21, 2008

Composer: Launch report from context menu


I have been looking into integrating a Composer solution with COGNOS. This note discusses how you launch a report from the context (right mouse button) menu of say a list of objects in a Query List. See the picture above.

There are two parts to this:
1. How to create a Report Service that registers in the context menu, and passes the correct parameters to COGNOS;
2. How to create a COGNOS report that accepts a parameter so that it reports on the one object.

Create the Report service

Lets assume that you have a split pane with a TQLQueryDefinition at the top and a TabularModelBrowser to display the results. You have created some buttons (like View or Edit) as ComponentServices under the parent DocumentShell, and these ComponentServices can be simply displayed at the bottom of the TabularModelBrowser and/or registered to appear in the context menu for a selected object. You now want to add a report into the Context menu so that you can fire off COGNOS to report on the specific object selected.

Steps:
1. Add a ReportListProvider under the document shell and set it to provide the report as a service
2. Add a ReportList under this. These reports will come up on the Context menu
3. Add reports to the report list as ReportInfo Objects
4. Configure the ReportInfo objects with the correct report URL to launch COGNOS. The way to do this is to go into the report properties in COGNOS and display the URL. Copy the URL from the start of the parameters onwards 
e.g. ?b_action ...
Remove the final parameter &cv.ccurl=1 and replace it with &nl=1
5. Put the correct javascript into the function fields.
For Is Valid Function use this:
return context.components && context.components.length==1;
This checks that one object (only) is selected

For Is Available Function use the same code. 

For the Get Parameters Function use this:

var cID = context.components && context.components[0]? context.components[0].id : null;
var paramMap = {"p_blueprint": context.blueprint.name, "p_ShowProps2": "Yes"};
if (cID) {
paramMap["p_PromptID"] = cID;
paramMap["run.prompt"] = "false";
}
return paramMap;


This code gets the object id and forms a parameter to add onto the URL sent to COGNOS. It adds this: 
&p_PromptID=myID&run.prompt=false

The PromptID parameter is the object's ID (myID, e.g. 220), and must match a COGNOS report parameter that filters the report to this object ID. 

The other parameter tells COGNOS not to prompt the user for this parameter.

Create the COGNOS report

Create the COGNOS report in Report Studio, but provide a filter query that depends on a parameter. In this case I was reporting on Applications, so I use a filter query like this:

[Model].[Applications].[Application Component ID] = ?PromptID?

This filters the report for only the Application Components with ID equal to my parameter, PromptID. This was the parameter that is inserted into the Composer generated report URL above by the Javascript. 

In the case of this report I also provided a prompt page to ask for this parameter so that the report could be run standalone, or used for a drill through. The URL parameter run.prompt=false suppresses this prompt page.


No comments: