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

Default Selection set as Current Month

Started by joecog, 07 Apr 2011 12:58:37 AM

Previous topic - Next topic

joecog

Hi,

I had a hierarchy where the Month hierarchy is as below :

[Ori].[Period][Period].[Month]

I had a Value Prompt that use value and display value point to the above hierarchy.

Would like to set the Default Selection as Current Month, may I know how to do this?

Format for Month is yyyy/mmm  eg: 2011/Mar


joecog

Hi

Anyone knows how to solve this?

Kindly help as it is urgent.


Thanks.

Joe

PRIT AMRIT

Assign a default selection to your prompt, say 1999/Jan

In your filter write the expression like below,

If ([Parameter]='1999/Jan')
then ([Current Month])
else ([Parameter])

NOTE: But when you first time run the report, your prompt would show the default value as 1999/Jan.

May some JS guys will help you out with a script though  ;)

Hope it helps?

Thanks
Prit

joecog

Hi Prit,

I had try the suggested but get the following error :

  Invalid coercion from 'level' to 'string' for '[Month]' in 'if ([Month] = '2011/Apr') then ([Current Mth]) else ([Month])'.

Any idea?


globalbear

Try this java script:

Call the prompt PeriodPrompt under Miscellanous and paste the code to a html object on the page.

<script type="text/javascript">

/*   Dynamic period prompt that works for period syntax 2011/Jan
   The prompt name (under Miscellanous - Name) must be PeriodPrompt
   The script originates from IBM: https://www-304.ibm.com/support/docview.wss?uid=swg21343424
   and has been modified by globalbear
*/


function init()
{
// how many months do you want to offset?
var perOffset = -1; // -1 is prev month, 0 is current month

// how many years do you want to offset?
var yearOffset = 0; // -1 is prev year, 0 is current year


var d = new Date();
var y = d.getFullYear();
var m = d.getMonth()+1+perOffset;

// add 12 if month is before January
var m2 = m <1 ? m +12 : m ;a

switch (m2){
case 1: m3 = '/Jan'; break;
case 2: m3 = '/Feb'; break;
case 3: m3 = '/Mar'; break;
case 4: m3 = '/Apr'; break;
case 5: m3 = '/May'; break;
case 6: m3 = '/Jun'; break;
case 7: m3 = '/Jul'; break;
case 8: m3 = '/Aug'; break;
case 9: m3 = '/Sep'; break;
case 10: m3 = '/Oct'; break;
case 11: m3 = '/Nov'; break;
case 12: m3 = '/Dec'; break;
}


//if month is before January - take away one extra year
var y2 = m < 1 ? y + yearOffset -1  : y + yearOffset ;


var dstr=y2+m3;

for (i=0; i < document.formWarpRequest._oLstChoicesPeriodPrompt.options.length; i++)
{
if
(document.formWarpRequest._oLstChoicesPeriodPrompt.options.text == dstr)
{
document.formWarpRequest._oLstChoicesPeriodPrompt.options.selected = true;
listBoxPeriodPrompt.checkData();
break;
}
}
}
</script>
<body onLoad=init()>

joecog

Hi globalbear,

I had add in the javascript give into the HTML object where the HTML item is put beside the value prompt (name as PeriodPrompt) but when run the report, the value prompt still not showing as 2011/Apr

Is there any steps that I miss out?

Joe

globalbear

Try this report.
I made a static period prompt with now query attached just to show the concept.
Change the package name in the xml before you paste it in a new report.

<report xmlns="http://developer.cognos.com/schemas/report/6.0/" expressionLocale="en">
            <modelPath>/content/package[@name='MY PACKAGE']/model[@name='model']</modelPath>
            <drillBehavior modelBasedDrillThru="true"/>
            <layouts>
               <layout>
                  <reportPages>
                     <page name="Page1">
                        <style>
                           <defaultStyles>
                              <defaultStyle refStyle="pg"/>
                           </defaultStyles>
                        </style>
                        <pageBody>
                           <style>
                              <defaultStyles>
                                 <defaultStyle refStyle="pb"/>
                              </defaultStyles>
                           </style>
                           <contents><HTMLItem>
         <dataSource>
            <staticValue>&lt;script type="text/javascript"&gt;

/*   Dynamic period prompt that works for period syntax 2011/Jan
   The prompt name (under Miscellanous - Name) must be PeriodPrompt
   The script originates from IBM: https://www-304.ibm.com/support/docview.wss?uid=swg21343424
   and has been modified by globalbear
*/


function init()
{
// how many months do you want to offset?
var perOffset = -1; // -1 is prev month, 0 is current month

// how many years do you want to offset?
var yearOffset = 0; // -1 is prev year, 0 is current year


var d = new Date();
var y = d.getFullYear();
var m = d.getMonth()+1+perOffset;

// add 12 if month is less then january
var m2 = m &lt;1 ? m +12 : m ;

switch (m2){
case 1: m3 = '/Jan'; break;
case 2: m3 = '/Feb'; break;
case 3: m3 = '/Mar'; break;
case 4: m3 = '/Apr'; break;
case 5: m3 = '/May'; break;
case 6: m3 = '/Jun'; break;
case 7: m3 = '/Jul'; break;
case 8: m3 = '/Aug'; break;
case 9: m3 = '/Sep'; break;
case 10: m3 = '/Oct'; break;
case 11: m3 = '/Nov'; break;
case 12: m3 = '/Dec'; break;
}


//if month is before january - take away one extra year
var y2 = m &lt; 1 ? y + yearOffset -1  : y + yearOffset ;


var dstr=y2+m3;

for (i=0; i &lt; document.formWarpRequest._oLstChoicesPeriodPrompt.options.length; i++)
{
if
(document.formWarpRequest._oLstChoicesPeriodPrompt.options.text == dstr)
{
document.formWarpRequest._oLstChoicesPeriodPrompt.options.selected = true;
listBoxPeriodPrompt.checkData();
break;
}
}
}
&lt;/script&gt;
&lt;body onLoad=init()&gt;</staticValue>
         </dataSource>
      </HTMLItem><selectValue name="PeriodPrompt" parameter="per"><selectOptions><selectOption useValue="2010/Dec"><displayValue>2010/Dec</displayValue></selectOption><selectOption useValue="2011/Jan"><displayValue>2011/Jan</displayValue></selectOption><selectOption useValue="2011/Feb"><displayValue>2011/Feb</displayValue></selectOption><selectOption useValue="2011/Mar"><displayValue>2011/Mar</displayValue></selectOption><selectOption useValue="2011/Apr"><displayValue>2011/Apr</displayValue></selectOption></selectOptions></selectValue></contents>
                        </pageBody>
                     </page>
                  </reportPages>
               </layout>
            </layouts>
         <XMLAttributes><XMLAttribute name="RS_CreateExtendedDataItems" value="false" output="no"/><XMLAttribute name="listSeparator" value="," output="no"/></XMLAttributes></report>

joecog

Hi ,

Just want to check with you, how do i open the XML that you pasted in Report Studio?

Sorry for asking such a simple question as I'm very new to Cognos.


Joe

joecog

Hi ,

I manage to open the sample in Report Studio.
Just want to check with you, the default selection is not showing the current month.

How do I set so that default selection is always point to the current month according to system date instead of manually changing it month by month?