COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: Deepsy on 26 Jan 2012 10:28:21 PM

Title: Auto Submit Default Date for a Date Prompt
Post by: Deepsy on 26 Jan 2012 10:28:21 PM
I have two date prompts, a start date and a finish date on a prompt page. The start date needs to be yesterday's date and the finish date should be today's date. I have managed to get that working through the following javascript:

<script type="text/javascript">
function DefaultDateSelection()
{
var fW = (typeof getFormWarpRequest == "function" ?getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined)
{ fW = ( formWarpRequest_THIS_ ?formWarpRequest_THIS_ : formWarpRequest_NS_ );
}

var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','A ug','Sep','Oct','Nov','Dec');

var ToTime=new Date();
var ToMonth=months[ToTime.getMonth()];
var ToDate= ToTime.getDate();
var ToYear=ToTime.getYear();
var ToDate = ToMonth + ' ' + ToDate + ', ' + ToYear;

var FromTime = ToTime;
FromTime.setDate(FromTime.getDate()-1);
var FromMonth=months[FromTime.getMonth()];
var FromDate= FromTime.getDate();
var FromYear=FromTime.getYear();
var FromDate = FromMonth + ' ' + FromDate + ', ' + FromYear;

pickerControlStartDate.setValue(FromDate);
pickerControlEndDate.setValue(ToDate);
}
DefaultDateSelection();
</script>

However, this report is part of a schedule and fails every time is run. The error message says dates were not specified.

Could anyone please advise where i'm going wrong? Is there an auto submit function that i'm missing out. I'm currently using Cognos 8.4.

Thanks!
Title: Re: Auto Submit Default Date for a Date Prompt
Post by: Grim on 27 Jan 2012 07:58:47 AM
You have to specify your prompt values when you schedule your report.
I'd create a separate report with hard coded prompts instead of javascript.

Depending on what DB vendor version your using you should be able to do "date - 1 day".
Title: Re: Auto Submit Default Date for a Date Prompt
Post by: tjohnson3050 on 27 Jan 2012 08:33:23 AM
I agree 100% with Grim

To expand just a bit - your java script fills in a default value on a prompt page.  With a schedule, when you set values for a prompt, it executes the prompt page once, and uses the value you select to satisfy the parameter.  That static value is then stored and used every time the scheduled report is executed.

As was suggested, remove the prompt from the report and replace it with logic.  You can use the following Cognos expression:

[your date field] between _add_days(current_date,-1) and current_date