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 !
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!
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 .
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
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,,,
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
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...
Was this ever resolved? I overcame most of issues like these in my environment. :D