COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: tupac_rd on 23 Sep 2011 11:08:41 AM

Title: javascript question
Post by: tupac_rd on 23 Sep 2011 11:08:41 AM
Hi Gurus,

For a text box prompt on the prompt page, we have javascript to set the previous month (for eg. 201108) if I run the report on any day in the month of September. The code used is below. The issue I am having is, the code works only when I run the report adhoc (Run Options -> View report). When I try to run the report in the background (Run Options -> Save report), the code doesn't work and the text box prompt is blank...

Can you please let me know what is missing in the code below, so that it works when running the report in the background...

<script>

var today = new Date();

var strVal = today.getMonth();

var strVal1 = today.getUTCFullYear();
if(strVal == 0)
(strVal1 = strVal1 - 1)
else (strVal1 = strVal1)


if(strVal < 10)
(strVal = "0" + strVal)
else (strVal = "" + strVal)

if(strVal == 0)
(strVal = "12")
else (strVal = strVal)


var strVal2  =  strVal1 + strVal;

getFormWarpRequest()._textEditBoxYYYYMM.value = strVal2;

</script>
Title: Re: javascript question
Post by: kattaviz on 06 Oct 2011 03:15:53 PM
Hi,

Try the following script.

<script>
var fW = (typeof getFormWarpRequest == "function" ?getFormWarpRequest() : document.forms["formWarpRequest"]);
// if it's undefined, check if it is running in a portlet
if ( !fW || fW == undefined)
{
fW = ( formWarpRequest_THIS_ ?formWarpRequest_THIS_ : formWarpRequest_NS_ );
}
var today = new Date();
var strVal = today.getMonth();
var strVal1 = today.getUTCFullYear();
if(strVal == 0)
(strVal1 = strVal1 - 1)
else (strVal1 = strVal1)
if(strVal < 10)
(strVal = "0" + strVal)
else (strVal = "" + strVal)
if(strVal == 0)
(strVal = "12")
else (strVal = strVal)
var strVal2  =  strVal1 + strVal;
fW_textEditBoxYYYYMM.value = strVal2;
</script>