COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: sthabinash on 08 May 2013 03:29:36 AM

Title: Set First Date and Last Date of date prompt dynamically
Post by: sthabinash on 08 May 2013 03:29:36 AM
I would like to set the first Date and Last Date properties of the Date prompt dynamically. I have searched for the JavaScript but all I have found was setting the default date of the Date prompt.

Can anyone help me on this.
Title: Re: Set First Date and Last Date of date prompt dynamically
Post by: Jiayue.lin on 08 May 2013 04:54:40 AM
this 2 javascripts are searched from internet, hope this may helps.

//the last day of the month
<script>
function ShowMonthLastDay()   
  {   
  var   Nowdate=new Date();   
  var   MonthNextFirstDay=new   Date(Nowdate.getYear(),Nowdate.getMonth()+1,1);   
  var   MonthLastDay=new  Date(MonthNextFirstDay-86400000);   
  var   strMonthLastDay = [MonthLastDay.getUTCFullYear(), MonthLastDay.getMonth()+1, MonthLastDay.getDate()].join("-");
  return strMonthLastDay;
  }
pickerControlPDate.setValue( ShowMonthLastDay() );
</script>



//the first day of the month
<script>
function subtractDay ()
{
var dtToday = new Date();
var strYesterday = [dtToday .getUTCFullYear(), dtToday .getMonth()+1, 1].join("-");

return strYesterday;
}
pickerControltext2.setValue( subtractDay() );
</script>
Title: Re: Set First Date and Last Date of date prompt dynamically
Post by: sthabinash on 08 May 2013 05:48:48 AM
Hello Jiayue.lin

The solution you mentioned will set only the default date of the date prompt and not set the range.   :'(
Title: Re: Set First Date and Last Date of date prompt dynamically
Post by: sharathhs on 19 Jun 2013 08:58:43 AM
Hi sthabinash,

Kindly let me know if you got any solution to set First date and Last date dynamically. I am also stuck with the same issue  :(

~Sharath
Title: Re: Set First Date and Last Date of date prompt dynamically
Post by: sthabinash on 01 Jul 2013 12:19:12 AM
Hello Jiayue.lin,

Sorry for the late reply, but I didn't find any solution to it. So had to drop the idea and find a way around it. If you find any solution to it please let me know as well. It might be helpful for future. Will let you know if I come across any solution.
Title: Re: Set First Date and Last Date of date prompt dynamically
Post by: Jiayue.lin on 01 Jul 2013 10:26:57 AM
sure...sthabinash... sorry i was busy these days...will try to solve it asap and let you know  :)
Title: Re: Set First Date and Last Date of date prompt dynamically
Post by: patrickthatcher on 28 Jan 2016 04:47:46 PM
I have a similar requirement.  Was this ever figured out?  For my requirement, I have query in the report that will provide the First and Last dates.
Thank you
Title: Re: Set First Date and Last Date of date prompt dynamically
Post by: BigChris on 29 Jan 2016 02:02:16 AM
This doesn't set the dates in the prompts, but it might give you an alternative approach...

http://cognostips.weebly.com/blog/date-prompts (http://cognostips.weebly.com/blog/date-prompts)
Title: Re: Set First Date and Last Date of date prompt dynamically
Post by: patrickthatcher on 29 Jan 2016 08:14:21 AM
Thanks. They really want the calendar to not allow the user to select a date earlier than the available data.
(vent time: even though we provide text below the calendar letting them know the earliest date! )
Title: Re: Set First Date and Last Date of date prompt dynamically
Post by: Lynn on 29 Jan 2016 09:44:47 AM
Another option to consider is checking the dates once they run the report and then conditionally rendering a page that lets them know they didn't pick a date within the available range. The "real" report pages would only render when they satisfy the date selections properly.

On the error page you could include a text item that says something like "Click here to try again". Put a drill through definition on the text item to call the same report. The report simply drills through to itself giving them the prompt page all over again where they will, hopefully, pay more attention to the instructions about the earliest available date. If you're in a crabby mood you could make the text say something a little more belligerent  ;)

Also note that when you develop a report that drills through to itself you'll need to save it each time before you run in Report Studio to test.