COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: arnoud on 23 Jul 2015 07:57:24 AM

Title: Javascript for value prompt not working in cognos viewer (portlet)
Post by: arnoud on 23 Jul 2015 07:57:24 AM
Hello ,

I have two java script to automatically select the first value from a check prompt. The second script automatically submits the prompt page, so the value selected is executed within the report.
The problem occurs when i connect this report to a Cognos viewer.

For some reason the scripts are not executed correctly within this viewer.

So if some can help me solve the problem that would be great.

The first script is:

<div id="msgDiv" style="color:chocolate; font-size:18"></div>
<script>
   // Attach functions to an arbitrarily named object to mimic a namespace to ensure the name uniqueness
   var zxcv = {};

   // Get the required prompt.
   var oCR = cognos.Report.getReport("_THIS_");
   var oP = oCR.prompt.getControlByName("promptbudgethouder");

   // Get the values and isolate the first value.
   var allValues = oP.getValues(true);
   var firstValue = allValues[0];

   // Set the prompt selection to the first value.
   oValues = [firstValue];
   oP.setValues(oValues);
</script>

The second script is:

<script type="text/javascript">

//get the form request
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);

if (fW)
{
  // if the report is running from reportStudio or the Portal objects are different
  if (fW.elements["cv.id"].value == "RS")
  {
     setTimeout('oCVRS.promptAction(\'Finish\')', 1000);
  }else{
    setTimeout('oCV_NS_.promptAction(\'Finish\')', 1000);
  }
}
</script>

regards,

Arnoud
Title: Re: Javascript for value prompt not working in cognos viewer (portlet)
Post by: Andrew Weiss on 23 Jul 2015 02:34:50 PM
Arnoud,

If you put a button on the report to invoke the script and then push the button after the report loads does it work properly?  If so you'll need to set your code to execute after the document is loaded (ready).  Here's an example of how to do that using JQuery.

https://learn.jquery.com/using-jquery-core/document-ready/

-Andy
Title: Re: Javascript for value prompt not working in cognos viewer (portlet)
Post by: arnoud on 27 Jul 2015 04:40:43 AM
Hello Andy,

thank you for the answer. But when i put a button to invoke the script within the report it isn't working.
When i put in the second script within the report it is working, but then the report is refreshing every time, and that is not suppose to happen.

Regards,

Arnoud