COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: Deeor on 16 Feb 2011 10:05:47 AM

Title: How to set a Value Prompt's default selection to a value in the DB2 table?
Post by: Deeor on 16 Feb 2011 10:05:47 AM
using vs. 8.4.1

I have two value prompts on the report page, one for year and one for month.

I want the value prompt's default selection to be the max(Year) and max(Month) that are available in the DB2 table. 

What is the javascript code to do this?

Thanks!
Title: Re: How to set a Value Prompt's default selection to a value in the DB2 table?
Post by: Deeor on 16 Feb 2011 12:04:26 PM
In case anyone else needs it, I found code that works!

<script type="text/javascript">
var promptValue;

var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);

if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}
var prompt = fW._oLstChoices<FieldName>;

// prompt.value.length will be 0 on load when nothing has been chosen
// This is the only time we want to set it or it will always return to our default value
if (prompt.value.length==0)
{


/* for (i = 0; i < prompt.options.length; i++)
{

alert(promptValue + ' ' + prompt.options[2].text)
if (prompt.options[2].text == promptValue)
{
prompt.options[2].selected = true;
}
}*/

prompt.options[2].selected = true;

promptAction('finish');

}
</script>