COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: Mark56 on 06 Sep 2011 09:47:39 AM

Title: Date Prompt - Default to YYYYMM
Post by: Mark56 on 06 Sep 2011 09:47:39 AM
I would like to default a prompt FY year/month selection to the current FY period.  Date dim has FY Period as YYYYMM field and that is what I am displaying. 

I would like to set the default selection for the prompt to always be that current FY period. 

Is there a way using the #prompt () # that this can be done in C8?  Thank you for any assistance in this matter
Title: Re: Date Prompt - Default to YYYYMM
Post by: rhythmz on 06 Sep 2011 12:01:49 PM
I recently did a report where the user wanted the begin_date prompt to automatically default the first day of the current month and the end_date prompt to default to the current system month. I solved this by using a HTML tag immediately after each prompt and defining the tag with the following JavaScript:

begin_date:
<script language="javascript">
//Default is today
var dDate = new Date();
dDate.setDate(1);
pickerControlStartDate.setValue(getFormatDate(dDate, 0 , 'YMD'));
</script>

end_date:
<script language="javascript">
var dDate = new Date();
//Get date 1 month later
dDate.setMonth(dDate.getMonth() + 1);
//Switch to first of next month
dDate.setDate(1);
//Subtract 1 to get last of current month
dDate.setDate(dDate.getDate() - 1);
pickerControlEndDate.setValue(getFormatDate(dDate, 0 , 'YMD'));
</script>

Now the trick is to go to properties pane of each prompt and the last field 'Miscellaneous" Name value gave the begin_date = StartDate and the end_date = EndDate (you will see this defined in the above code for each prompt).

I got this tip from "IBM Cognos 8 Report Studio Cookbook" by Abhishek Sanghani on PACKT Publishing. I hope you can play around with this and see what happens.

Title: Re: Date Prompt - Default to YYYYMM
Post by: rhythmz on 06 Sep 2011 12:03:59 PM
Here is an IBM link that may help:

https://www-304.ibm.com/support/docview.wss?uid=swg21342809