JavaScript stopped working in Cognos portal

Today I got a call from a friend. Shortly before going to production it was noticed that a report that works flawlessly from Report Studio, and from clicking on the report link in the portal, doesn’t work in the Cognos Portal.

The report relies on JavaScript to alter the prompts. When he runs the report from RS, everything is beautiful. Prompt headers are removed, default options are set, and everything behaves as expected. However, once the report was placedin a Cognos Viewer portlet in the portal an “Object Expected” error would be thrown every time the report was run.

It turns out there are several significant differences between the Report Viewer (from RS) and the Cogons Viewer (what’s used in the portlets). I cordially invite (okay, I’m begging. I really don’t want to go through a few thousand lines of JS.) any actual Cognos Devs to explain the differences between RV and CV.

An example of the original code:

<script language="javascript">
var f = getFormWarpRequest();
var list = f._oLstChoicesPrompt_Years;

list.remove(1);
list.remove(0);
list.removeAttribute("hasLabel");

canSubmitPrompt();
</script>

It removes the first two rows from the prompt (prompt label and the —), then removes the “hasLabel” attribute (which prevents those two rows values from being selected).

The corrected code is:

<script language="javascript">
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined)
   { fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}

var list = fW._oLstChoicesPrompt_Years;

list.remove(1);
list.remove(0);
list.removeAttribute("hasLabel");

canSubmitPrompt();
</script>

It was a very simple adaptation of the code found at IBM here.

This method will work in all versions from 8.3 and above (at least until they change the engine again).

Back To Top