Академический Документы
Профессиональный Документы
Культура Документы
14 November 2012
This document describes a technique to set dynamic default values for date prompts using a
combination of prompt macros and JavaScript.
View more content in this series
Introduction
Purpose of Document
This document describes a technique to set dynamic default values for date prompts using a
combination of prompt macros and JavaScript.
Applicability
The technique outlined in this document was validated using IBM Cognos BI 10.2 and the GO
Sales(query) sample package.
Trademarks
Page 1 of 5
developerWorks
ibm.com/developerWorks/
For this example the requirement is to have the report default to the last 90 days based on the
current date the report is executed.
1. Create two detail filters on the Query which is used by the List with the following definitions.
Filter Name: FromDate
Filter Expression:[Sales (query)].[Time].[Date]>=(#prompt('FromDate','date',
'(_add_days (current_date,-90))')#)
2. Ensure the Usage property for the detail filters is changed from Required to Optional. When
completed the Query Explorer screen should have Product line and Revenue within the Data
Items pane and two filters in the Detail Filters pane. This is illustrated in Figure 1.
Figure 1 - IBM Cognos Report Studio Query Explorer displaying the Data
Items and Detail Filters
Page 2 of 5
ibm.com/developerWorks/
developerWorks
3. From the Toolbox pane, drag a Date Prompt object onto the report canvas above the List
object.
4. When prompted, select the Use existing parameter radio button.
5. From the Use existing parameter drop down box, select the FromDate prompt name and click
the Finish button.
6. Within the right hand report canvas pane, click on the date prompt previously inserted. Within
the Date Prompt properties pane, set the Name property to PDateFrom.
7. Also within the Date Prompt properties pane, switch the Select UI property from Calendar to
Edit box.
Figure 2 illustrates the Date Prompt properties pane for the FromDate parameter with the
Name property set to PDateFrom and the Select UI property set to Calendar.
Figure 2 - IBM Cognos Report Studio Date Prompt properties pane for the
FromDate parameter
8. Repeat steps 3 to 7 within this section for the ToDate parameter, setting the Name property
name of PDateTo.
9. From the Toolbox pane, drag a Prompt Button onto the report canvas next to the two date
prompt objects above the List object.
10. Click on the Prompt Button and in the Properties pane, change the type from Next to Finish.
Page 3 of 5
developerWorks
ibm.com/developerWorks/
<script type="text/javascript">
var fdf = getFormWarpRequest();
var listDateFrom = fdf.txtDatePDateFrom
var ftp = getFormWarpRequest();
function last90Days()
{
var ndays = 90;
var dtToday = new Date();
var dtlast90Days = new Date (dtToday - (86400000*(ndays)));
var strlast90Days = [dtlast90Days.getUTCFullYear(), dtlast90Days.getMonth()+1,
dtlast90Days.getDate()].join("-");
return strlast90Days;
}
pickerControlPDateFrom.setValue(last90Days() );
</script>
Page 4 of 5
ibm.com/developerWorks/
developerWorks
Page 5 of 5