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).
Hi,
I am using the same code but it is not working .
———–Please find code below:……………————–
function AS()
{
var fW1 = (typeof getFormWarpRequest == “function” ? getFormWarpRequest() : document.forms[“formWarpRequest”]);
if ( !fW1 || fW1 == undefined)
{ fW1 = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}
// fW1._oLstChoicesMyFieldName.selectedIndex = 0;
var preFix = “”; if (fW1.elements[“cv.id”])
{ preFix = fW1.elements[“cv.id”].value; }
var fW1 = getFormWarpRequest();
var dropDownL3 = fW1._oLstChoicesXYZ1;
var d = new Date();
//var dropDownA = fW1._oLstChoicesA;
//dropDownA .value=”1″;
var x =d.getDate();
if(x>7)
{
dropDownL3.value=”0″;
}
else
{
dropDownL3.value=”1″;
}
setTimeout(“promptButtonFinish();”,0);
}
function displayWeek()
{
if (getFormWarpRequest()._oLstChoicesA.value ==”0″)
{
AS();
}
}
Please help.
Regards
Hi Atul,
You’re defining fw1 correctly, but immediately afterwords you’re redefining it back to getFormWarpRequest().
My suggestion is create an HTML item with this script:
Then your remaining scripts could look like:
Hi Paul,
I have used your modified script to remove first 2 lines in the value prompt. It works great in IE, but it stops working in FireFox (running in Cognos Viewer portlet) after I make a selection.
The value prompt is on the report page with AutoSubmit set to Yes. The first time I open the portal page, the first 2 lines don’t show up as expected. The minute I select a value from the prompt and report re-runs, the first 2 lines are comming back. I have tested in FireFox 3.6 and 5.0.
Here is the script I have used:
—————————————————————————————-
var fW = (typeof getFormWarpRequest == “function” ? getFormWarpRequest() : document.forms[“formWarpRequest”]);
if ( !fW || fW == undefined) {
fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}
var list = fW._oLstChoicesP2;
list.remove(1);
list.remove(0);
list.removeAttribute(“hasLabel”);
canSubmitPrompt();
——————————————————————————————
Hi Olga,
I just create a quick report to test this, but it still works fine on my end with Firefox 3.6. Do you have any JavaScript anywhere else on the page? My guess is the JavaScript interpreter is failing somewhere.
Install the Firebug add-on and run the page with Firebug open to the Scripts tab. If there is a JavaScript error anywhere on the page you’ll see exactly what it is.
Hi Paul,
I have used the script provided above. I have a multi page dashboard board with 11 reports in two folders
After modifying the script it works fine for the first report and in remaining reports its not working..Please suggest
Hi Kamal,
Make sure you give each element in the reports unique ids. Multi page dashboards are essentially a single HTML page, so getElementById will only reference the first existing element with any given ID.
Hi Paul,
I have used the similar code you have given above, it works fine in IE for both RS and portals, but in FF it does not work for portal.
Code:
var fW =(typeof getFormWarpRequest == “function” ? getFormWarpRequest() : document.getElementById(‘formWarpRequest’));
if ( !fW || fW == undefined)
{ fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}
var choices1= fW._oLstChoicesPrompt1;
var choices1_Absolute_Percent = fW._oLstChoicesPrompt_Absolute_Percent;
check(choices1,choices1_Absolute_Percent);
choices1.onchange=check;
function check(choices1,choices1_Absolute_Percent )
{
var idx=choices1.options.selectedIndex;
if ( choices1.options[idx].value == ‘Married’ || choices1.options[idx].value == ‘Has Children’ )
choices1_Absolute_Percent.disabled=true;
else
choices1_Absolute_Percent.disabled=false;
}
check_AP();
choices1_Absolute_Percent.onchange = check_AP;
function check_AP( )
{
var idx_AP=choices1_Absolute_Percent.options.selectedIndex;
if ( choices1_Absolute_Percent.options[idx_AP].value == ‘Percent’)
choices1.disabled=true;
else
choices1.disabled=false;
}
Error on FF is “Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.”
its on line : “if ( !fW || fW == undefined)
{ fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );} ”
Thanks
Irfan
Hi Paul,
I have a scenario where I want to conditionally display/hide the subtotals in a list;based on comma separated input (CSV) in textbox prompt.
For e.g. we have a list with 3 columns: Prod Line code (Grouped), Prod type and Revenue (Summary/sub-total @ Prod Line Code) and a textbox prompt for CSV input. Whatever Product Line Code(s), I input in this prompt in CSV format, only for those PLCs, we should show the subtotals (list row) and rest should be hidden.
The approach that I have taken is validating the CSV input through Javascript and pass it to a hidden value-prompt where all PLCs pre-populated and can be multi-selected. Only the common values to Textbox and Value prompts are selected upon a button-click.
Then using a boolean variable (where there is condition ) as style-variable, I set the box-type=None for list-subtotal-row. But I’m having two problems here:
1. The boolean condition considers only single PLC value so one subtotal is shown ignoring the rest
2. The page gets submitted only once (upon calling promptFinishButton()) but not subsequent button-clicks. I’m using HTML Input Type and not Cognos’ standard prompt button
Can you please assist or suggest another approach?
Paul,
Thank you. I was going crazy with this one trying to limit the number of entries in a multiselect text box prompt. I was trying to go for an if != “undefined” oCV, oCV_NS_ and oCVRS in the finish button, but then I was getting an object expected error on thegetFormWarpRequest. This makes it much easier.
Thanks again
-dan.
Hi Paul,
I am not able to run this script in Cognos 10.2. It shows me list (variable) is null Error.
var fW = (typeof getFormWarpRequest == “function” ? getFormWarpRequest() : document.forms[“formWarpRequest”]);
if ( !fW || fW == undefined)
{
fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );
}
var list = fW._oLstChoicesExcNoted;
// alert(list);
list.remove(1);
list.remove(0);
list.removeAttribute(“hasLabel”);
canSubmitPrompt();
Please help.
Thanks,
Rohit
Hi Rohit,
As of Cognos 10.1 there’s an easier way of doing this. In the properties of the prompt, scroll down until you see the “Prompt Text” section. Doubleclick on the Header Text row, and select specified text. Leave it blank and Cognos will automatically remove the first two rows.
We have a report which is working fine but when we add this report on dashboard java script is not working. Java script is used to pick the latest date from prompt and this prompt is optional. Please suggest
Hello Paul,
Can a portal tab handle same function across all reports? I’m having a weird issue here. I’m using animated dropdown prompts javacript( thank you providing this excellent capability) in all my reports. Most of the prompts are similar in all the reprots like year, month etc but the reports may or may not be based on the same cube. So the issue is if I move from one tab to another without letting the previous one load completely, I cannot make any selections meaning the tab freezes until I hit refresh icon on cognos connection. I cannot apply any of my prompt choices. Any ideas what could be causing this?
Also, I using the dashboard object( multipage) and linking it to the folder where I have all my reports. Then I add it to my portal tab.