COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: Anand on 04 May 2008 08:17:06 AM

Title: Default selection in the value prompt
Post by: Anand on 04 May 2008 08:17:06 AM
Hi All,
How to get dynamic max year(ex:2008) as default selection in the value prompt when i run the report.

Regards,
Anand.
Title: Re: Default selection in the value prompt
Post by: kattaviz on 04 May 2008 09:17:08 AM
Hi,
U can do that using javascript. Get the values from listbox in a array and sort the array elements. Once u got the max value from array assign that value to listbox selected item. Please let me know if u need more info.
I can post the code tomorrow if u want.


HTH
thanks

Title: Re: Default selection in the value prompt
Post by: Anand on 04 May 2008 09:26:47 AM
Hi Satish,
Thanks for sending the reply and i am displaying that value prompt in the report page itself and they are in sorting order only(2006,2007,2008,2009,2010) and please send me the java script and when i run the report it should display by current year and after that we can change that from the prompt available in the report header.

Regards,
Anand.
Title: Re: Default selection in the value prompt
Post by: kattaviz on 20 May 2008 02:59:11 PM
Hi Anand,

Please see the following script for ur solution.

---------------
var lb = document.getElementById('formWarpRequestRS')._oLstChoicesXXX;
arrTexts = new Array();
for(i=0; i<lb.length; i++)  {
  arrTexts = lb.options.text;
}
arrTexts.sort();
var len=arrTexts.length-1;
document.getElementById('formWarpRequestRS')._oLstChoicesXXX.options[len].selected=true;

---------------

Where XXX is the name of the Value prompt. Sorry for the delay. I was travelling and did not access the forum.
Title: Re: Default selection in the value prompt
Post by: kattaviz on 20 May 2008 03:32:50 PM
Quote from: kattaviz on 20 May 2008 02:59:11 PM
Hi Anand,

Please see the following script for ur solution.

---------------
var lb = document.getElementById('formWarpRequestRS')._oLstChoicesXXX;
arrTexts = new Array();
for(i=0; i<lb.length; i++)  {
  arrTexts = lb.options.text;
}
arrTexts.sort();
var len=arrTexts.length-1;
document.getElementById('formWarpRequestRS')._oLstChoicesXXX.options[len].selected=true;

---------------

Where XXX is the name of the Value prompt. Sorry for the delay. I was travelling and did not access the forum.
If u already sort the query for the prompt then u do not need to sort the array in javascript code. remove the line "arrTexts.sort();"
Title: Re: Default selection in the value prompt
Post by: almeids on 21 May 2008 08:28:23 AM
And if you sort descending you don't need any logic to determine the list size, just select the first element.
Title: Re: Default selection in the value prompt
Post by: chris2001dc on 02 Jun 2009 09:56:13 AM
Hi,

Does the javascript code posted here works in Cognos 8.3??

Thanks