COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: sri44 on 19 Feb 2010 04:45:06 PM

Title: How to set value to a parameter using javascript in Cognos 8.3 report studio
Post by: sri44 on 19 Feb 2010 04:45:06 PM
How to set value to a parameter using javascript in Cognos 8.3 report studio

i need to get the  selected Paramater value from value prompt if nothing is selected i need to default it to some junk value for the Parameter.


i know we can access the parameter by java script by p_<parameterName>
but its not helping  me out !

Please help me out !


Title: Re: How to set value of parameter using javascript in Cognos 8.3 report studio
Post by: rlp on 20 Feb 2010 07:00:48 AM
First, select the value prompt in Report Studio and assign it a Name (such as MyPrompt).

Once that is done, add an HTML Item to the page with this bit of JavaScript:

<script type="text/javascript">
var fW = getFormWarpRequest();
var prompt = fW._oLstChoicesMyPrompt;
if ( prompt && prompt.options.length > 2 && prompt.options.selectedIndex == 0 ) {
  prompt.options.selectedIndex = 3;
}
</script>


NOTES:

The call to getFormWarpRequest() is the recommended way to access the Cognos form (and its prompts), but may not work in all cases (such as when running directly from Report Studio).  You may want to use this code instead:

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

You can also search the prompt options in a loop if you want to locate and select a specific value instead of just selecting the first available value.

Good luck!
Title: Re: How to set value to a parameter using javascript in Cognos 8.3 report studio
Post by: sri44 on 22 Feb 2010 10:04:08 AM
Hi rlp ,

Thanks for the Reply,
But i need to set a junk value to the parameter of Value Prompt if nothing is selected .

so i need to assign a value to the Paramter using java script .
Title: Re: How to set value of parameter using javascript in Cognos 8.3 report studio
Post by: rlp on 22 Feb 2010 06:26:01 PM
Sounds like you want to inject a new value into the prompt and then select it.

If so, that can be done using standard DOM manipulation.  Is that what you are trying to do?

Randy
Title: Re: How to set value of parameter using javascript in Cognos 8.3 report studio
Post by: dhavcog on 22 Feb 2010 06:38:56 PM

just got confused by saying Junk value (what is mean by),,

anyway,, what i can do select parameter and setting default value as your junk value ,,

so it there will be no any inputs from user, your junk value will be used,, (if i understand  your problem right ?)

try it,, let me know,,,
Title: Re: How to set value of parameter using javascript in Cognos 8.3 report studio
Post by: sri44 on 24 Feb 2010 10:13:35 AM
Just i want assigned some value to parameter using javascript
actually i got prompts which r optional i cannot make them required ,
If one prompt is not selected i need to filter query in the report

so i need like this if prompt is selected ---> Parameter value is null then I need to assign any value to that parameter so that i can check this one  in the Filter ( I tried using default value in Prompt Properties its not Working in this scenerio)

so i need to set some value to Parameter if parameter value is null using Java Script !!

Some thing like this

<script>
Functon Test()
{

var Param=p_Param_sales_market;
if(param is null) then(param='123')

}


</script>


<this must be done on Click Finish button>

thanks
Title: Re: How to set value of parameter using javascript in Cognos 8.3 report studio
Post by: rlp on 26 Feb 2010 04:24:55 PM
Okay, in that case try something like this...

Step 1: Add two HTML Items around the Finish button with <span="FinishBtnID">...</span>.

Step 2: Add this JavaScript to the report.

function setVariableOnClick( fw, formVariable, newValue ) {
  var btn = document.getElementById('FinishBtnID').getElementsByTagName('button')[0];
  var prev_handler=btn.onclick;
  btn.onclick = function(e) {
    var field;
    for ( var i = 0; i < fw.elements.length; i++ ) {
      if ( fw.elements.name = 'p_' + formVariable ) { field = fw.elements; break; }
    }
    if (field && (!field.value || (field.value.indexOf('run') === 0))) field.value = newValue;
    prev_handler(e);
  }
}

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

setTimeout( 'setVariableOnClick( fW, "ParamName", "Junk" )', 100 );

NOTE: The setTimeout is needed if the Finish button is in the footer...
Title: Re: How to set value to a parameter using javascript in Cognos 8.3 report studio
Post by: lazolam@gmail.com on 12 Jun 2013 07:44:53 AM
Was this ever resolved? I overcame most of issues like these in my environment. :D