If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

How to display Previous Month as Default in value prompt using Java script?

Started by cognosbi.dwh, 11 Jan 2012 04:41:19 AM

Previous topic - Next topic

cognosbi.dwh

Hi,

I have Calender table & with columns Fiscal_Year,Civil_Month in Database 

Fiscal_Year values are ex:- 201101,201102,201103,.....,201201,201202,....
Civil_Month values are ex:- Jan-11,Feb-11,Mar-11,.....,Jan-12,Feb-12,....

I created prompt for Fiscal_Year as use value fiscal_year,display value civil_Month icchanu

if i run the report prompt values as like:  civil_month,Jan-11,Feb-11,.......

My client Requirement is If he runs the report in Jan-12
then the prompt default display value should be previous month i.e., Dec-11 have to select from prompt

So whenever he runs the report the default value should be prvious month which is select from prompt(i.e.,prompt.selectIndex)

For this I used Java script as below...but its not working


HTML Object
<span id="A1">

Value Prompt

HTML Object
</span><script>
var theSpan = document.getElementById("A1");
var a = theSpan.getElementsByTagName("select");
var currentTime = new Date()
var month = currentTime.getMonth()
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var str=year+month.toString();
if(month==1)
{
month=12;
year=year-1;
}

for( var i = a.length-1; i >= 0; i-- )
{ var prompts = a;

if( prompts.id.match(/PRMT_SV_/))
{
prompts.selectedIndex = month;
prompts.options[0].text = 'Civil_Month'; /* This is
the new line added to script */
}
canSubmitPrompt();
}
</script>

am poor at java script

Its very urgent requirement. Can anyone help me in this please....

Reply me to <SNIP> It's a bad idea to give out your email address. Spammers might see them. -PaulM


Thanks,
Swetha
Thanks,
Swetha

CognosPaul

First, which version of Cognos are you using? Also, which database?

Does the user want it to be deducting one month only for January, or for every month?

There's another step you're missing in your request.

When you use JavaScript to modify a prompt, the change will only take effect after the page has been rendered. If this prompt object is on the prompt page, then it's not a problem. But if the prompt exists as part of the report itself, or if you want to schedule the report, then this won't work. You need to put the logic in the prompt macro in the default parameter.

Something like #prompt('Parameter','integer','extract (year,_add_months(current_date,-1)) *100 +extract (month,_add_months(current_date,-1)) ')#

cognosbi.dwh

Hi,
Am using Cognos 8.4 version & SQL Server Database

My user wants to deduct one month for every month
Am Using the prompt in prompt page only

I had created 2 value prompts in a prompt page based on Fiscal_Year(use value),civil_Month(display value)
Query1 as Year1,Query2 as Year2.
In Query2 I had created filter as
[Fiscal_Year_Month]=(extract(year,(_add_months(current_date,1)))*100+ extract(month,(_add_months(current_date,1))))

and I added java script in html object in prompt page as
<script type="text/javascript">
function init()
{
document.formWarpRequest._oLstChoicesYear2.options[2].selected = true;
document.formWarpRequest._oLstChoicesYear1.value = document.formWarpRequest._oLstChoicesYear2[2].value ;
}
canSubmitPrompt();
</script>
<body onLoad=init()>

Now I set Year2 prompt as invisible. Now am getting Previous Month value.
Every Thing is working fine.
But If i run the report it displaying one pop-up window as ! warning message- one or more of the values required is missing .Required values are needed to produce the report.

I dont want to show that pop-up window to the user.
How can I hide This pop-up window

can you please provide any java script for this or else any idea.

Thanks,
Swetha


Quote from: PaulM on 11 Jan 2012 05:46:06 AM
First, which version of Cognos are you using? Also, which database?

Does the user want it to be deducting one month only for January, or for every month?

There's another step you're missing in your request.

When you use JavaScript to modify a prompt, the change will only take effect after the page has been rendered. If this prompt object is on the prompt page, then it's not a problem. But if the prompt exists as part of the report itself, or if you want to schedule the report, then this won't work. You need to put the logic in the prompt macro in the default parameter.

Something like #prompt('Parameter','integer','extract (year,_add_months(current_date,-1)) *100 +extract (month,_add_months(current_date,-1)) ')#
Thanks,
Swetha

CognosPaul

If the JavaScript only takes effect on the prompt page then you don't need to worry about default values in the prompt macro.

The JavaScript you're using modifies the prompt selection, but it doesn't perfectly mimic the events which occur when a user clicks on the prompt element. The value is selected, but Cognos hasn't been told that the prompt is now in a valid state, so it will pop up that message.

The easiest way to solve this is by adding canSubmitPrompt(); after all of the prompt manipulations.

Look here for more information.

cognosbi.dwh

Hi Paul,
Its not working perfectly. If I run only prompt page it showing previous month as display in value prompt. If I run the report  it showing as civil_month,values...

Is there any other way to solve this,please let me know
Thanks,
Swetha