Author Topic: Disable selecting holidays (date prompt)  (Read 11360 times)

Offline stancho

  • Senior Member
  • ****
  • Join Date: Nov 2010
  • Posts: 63
  • Forum Citizenship: +0/-1
Disable selecting holidays (date prompt)
« on: 14 Jan 2011 02:41:29 am »
Hi all,

I have some reports with DatePicker prompts.
How can I create something like custom calendar in Report Studio (using javascript or some cognos techniques)?
I want to disable selecting holidays (ex. Saturdays and Sundays). I also would like to disable selecting custom national holidays (but only for Saturdays and Sundays would be enough).

If it's not possible to disable these values I would like if somebody choose Saturday the report will show the data for the last working day (ex. Friday).

Any ideas?

BR,
Stancho

Offline Lynn

  • Statesman
  • ******
  • Join Date: Apr 2008
  • Posts: 2,701
  • Forum Citizenship: +341/-1
Re: Disable selecting holidays (date prompt)
« Reply #1 on: 14 Jan 2011 08:00:10 am »
Do you have a date dimension that identifies work days vs. non-work days? One possible option is to use a value prompt control instead of a date picker that would only present the valid days. Not terribly elegant, I realize. This would not be a good idea if you have tons of dates to choose from.

If you stick with the date picker, can't disable the days (don't get me started with JS), and don't have a date dimension then you can modify your filter condition in the report to account for saturdays and sundays:

Create a data item "filterDate" in the query:
Code: [Select]
if ( _day_of_week(?PickDate?,1) in (6, 7) )
then ( _add_days(?PickDate?,5-_day_of_week(?PickDate?,1)) )
else ( ?PickDate? )

The above says if the day of the week selected is Saturday (6) then back it up by one day (5 - 6). If it is Sunday (7) then back it up by two days (5 - 7). Otherwise the date is fine as is.

Set the filter condition:
Code: [Select]
[YourDateItem] = [filterDate]
If you have a date dimension that identifies work days vs. non-work days and also has an attribute for the previous work day then you are a lucky SOB and should run out immediately to buy a lottery ticket.

Offline stancho

  • Senior Member
  • ****
  • Join Date: Nov 2010
  • Posts: 63
  • Forum Citizenship: +0/-1
Re: Disable selecting holidays (date prompt)
« Reply #2 on: 14 Jan 2011 10:12:36 am »
Lynn thanks for this answer!

I need Date Picker. Because I have a lot of days (years).

I have two quensions about your solution:

1. If I choose 02.06.2010 If I set:
( _add_days(?ForDate?,-1) ) the date will be 01.06.2010 00:00:00
But If use ( _add_days(?ForDate?,(... - _day_of_week(?ForDate?,1))) ) the date will 01.06.2010 (not a datetime)?

2. Is there a way to use this filter globally or I should add it in every query in every report?

Thanks,
Stancho

Offline Lynn

  • Statesman
  • ******
  • Join Date: Apr 2008
  • Posts: 2,701
  • Forum Citizenship: +341/-1
Re: Disable selecting holidays (date prompt)
« Reply #3 on: 14 Jan 2011 10:24:56 am »
Hi Stancho,
I guess you don't have a date dimension to work with...

I'll try to answer your questions:
1. Not sure I understand exactly what your issue is, but assuming you don't need users to specify a time, then use a Date Prompt and NOT a Date & Time Prompt. If you use the Date Prompt control then you shouldn't see timestamps. That said, what is the data type in your database that you'll be comparing the selection to? If it is date time then you'll want to cast it to a date only in order to compare apples with apples.

2. I don't know what queries you have in your report but probably you'll need it in all of them. If you have two queries joined together to form a third, then possibly you'd only need the filter in the two base queries and not in the joined query. There isn't a global approach as far as I know.

Good luck!

Offline melee

  • Community Leader
  • *****
  • Join Date: Oct 2010
  • Posts: 95
  • Forum Citizenship: +4/-0
  • Running on the steam of apathy
    • Beautiful Data with COGNOS and jQuery
Re: Disable selecting holidays (date prompt)
« Reply #4 on: 14 Jan 2011 10:30:38 am »
can't disable the days (don't get me started with JS)

Lynn, now that you're my COGNOISe JS pal, I have an idea to solve this quickly and elegantly.

Check out this concept:

1. Create two text value prompts, one for dateBegin and one for dateEnd, or just date if you only need a single day. Create the appropriate filter on the hidden prompts
2. Using JS, set their display:none to hide them
3. Use the jQuery UI datepicker (http://jqueryui.com/demos/datepicker/) on an empty div to create a calendar
4. Add holidays to the function (not the prettiest part, see http://stackoverflow.com/questions/2921848/disable-list-of-holidays-in-jquery-date-picker), then when a date is selected, populate the hidden prompt from step 1 with that information
5. Submit.

I'd be happy to detail this step-by-step if it seems helpful - it'd actually be pretty elegant.
6.

Offline Lynn

  • Statesman
  • ******
  • Join Date: Apr 2008
  • Posts: 2,701
  • Forum Citizenship: +341/-1
Re: Disable selecting holidays (date prompt)
« Reply #5 on: 14 Jan 2011 10:36:54 am »
Quote
my COGNOISe JS pal
:D

I am sure Stancho will appreciate some knowledgeable help on the JS options for this!

I couldn't even write correct syntax for the joke JS I did in the other thread but decided poetic license ought to apply even to JavaScript.

Offline MFGF

  • Never knowingly correct
  • Super Moderator
  • Statesman
  • ******
  • Join Date: Jul 2005
  • Posts: 10,996
  • Forum Citizenship: +653/-10
  • Cognos Software Muppet
Re: Disable selecting holidays (date prompt)
« Reply #6 on: 14 Jan 2011 11:21:32 am »
I couldn't even write correct syntax for the joke JS I did in the other thread but decided poetic license ought to apply even to JavaScript.

What???  It was a joke?
Meep!

Offline Lynn

  • Statesman
  • ******
  • Join Date: Apr 2008
  • Posts: 2,701
  • Forum Citizenship: +341/-1
Re: Disable selecting holidays (date prompt)
« Reply #7 on: 14 Jan 2011 11:51:45 am »
What???  It was a joke?

MF, the JS I gave you was not a joke.

I, uh, was referring to a completely different thread on a totally different forum  ;) ::)

Offline melee

  • Community Leader
  • *****
  • Join Date: Oct 2010
  • Posts: 95
  • Forum Citizenship: +4/-0
  • Running on the steam of apathy
    • Beautiful Data with COGNOS and jQuery
Re: Disable selecting holidays (date prompt)
« Reply #8 on: 14 Jan 2011 12:19:56 pm »
Ok, I've attached the report. Feel free to give it a go (we're running 8.4).

You'll need to get the CSS file from jqueryui.com - very easy though.

I posted a (rushed) tutorial on the whole thing here:

http://nicbertino.com/?p=41
« Last Edit: 14 Jan 2011 12:30:24 pm by melee »

Offline stancho

  • Senior Member
  • ****
  • Join Date: Nov 2010
  • Posts: 63
  • Forum Citizenship: +0/-1
Re: Disable selecting holidays (date prompt)
« Reply #9 on: 17 Jan 2011 02:57:59 am »
melee, thanks a lot for this.

I will check it now!

BR,
Stancho

 



       
Twittear