Author Topic: Create Pop-up Warning or Restrict Date Prompt  (Read 347 times)

Offline Magdalina08

  • Full Member
  • ***
  • Join Date: Oct 2019
  • Posts: 7
  • Forum Citizenship: +0/-0
Create Pop-up Warning or Restrict Date Prompt
« on: 10 Oct 2019 12:44:19 pm »
Hi all, new to the group, though I often use this wonderful site for help with my Cognos questions!  Thanks! 

I have a client requirement that I haven't been able to find a solution for.

I have a date range prompt.  I need to insert a pop up warning or prevent a user from selecting "Finish" with pop up when the user selects 365 days worth of data.  I know Javascript can be inserted into HTML tags.  Can anyone help with finding the best method for this? 

I think I need to count the number of days between dates selected and then pop up or restrict if x=365.  How do I reference the date range on a prompt? Should I use two single date prompts and then count the days between those?  Or is there an easier method that I am overlooking?  It seems to me that this is not a crazy or unheard of ask.
« Last Edit: 11 Oct 2019 11:46:00 am by Magdalina08 »

Offline Francis aka khayman

  • Statesman
  • ******
  • Join Date: Jun 2009
  • Posts: 480
  • Forum Citizenship: +25/-3
    • CognosM
Re: Create Pop-up Warning on Date Prompt with Javascript
« Reply #1 on: 10 Oct 2019 12:54:05 pm »
two things immediately pop out of my head...

1. do not pop up a warning. use the restrict option... if days >= 365 then 364 else days
2. create two prompts for date range, start_date and end_date. then cascade them. filter end date so that the options available will not be more then 365 days from the start_date chosen

Offline Magdalina08

  • Full Member
  • ***
  • Join Date: Oct 2019
  • Posts: 7
  • Forum Citizenship: +0/-0
Re: Create Pop-up Warning on Date Prompt with Javascript
« Reply #2 on: 10 Oct 2019 03:24:48 pm »

1. do not pop up a warning. use the restrict option... if days >= 365 then 364 else days
2. create two prompts for date range, start_date and end_date. then cascade them. filter end date so that the options available will not be more then 365 days from the start_date chosen

Thanks for the response!

I tried the first option but seem to be having some syntax issues with it.  It is not letting me use the days function in a filter. 

For the second option you suggested, date prompts do not allow for cascading.

Offline Francis aka khayman

  • Statesman
  • ******
  • Join Date: Jun 2009
  • Posts: 480
  • Forum Citizenship: +25/-3
    • CognosM
Re: Create Pop-up Warning on Date Prompt with Javascript
« Reply #3 on: 10 Oct 2019 04:15:44 pm »
hold on.

1. you are using _add_days function aren't you?
2. i have to agree this is not feasible. you can use normal prompt and convert to date but that would be too much work...

Offline Magdalina08

  • Full Member
  • ***
  • Join Date: Oct 2019
  • Posts: 7
  • Forum Citizenship: +0/-0
Re: Create Pop-up Warning on Date Prompt with Javascript
« Reply #4 on: 11 Oct 2019 11:14:35 am »
I tried the days function for DB2, _days_between, and _add_days.  The _add_days will not work because this simply adds a day to the date selected. 

Still trying to find a feasible solution to this. 

Offline Francis aka khayman

  • Statesman
  • ******
  • Join Date: Jun 2009
  • Posts: 480
  • Forum Citizenship: +25/-3
    • CognosM
Re: Create Pop-up Warning on Date Prompt with Javascript
« Reply #5 on: 11 Oct 2019 11:45:33 am »
math 101... if you add a negative number, it will actually result to subtraction.

I tried the days function for DB2, _days_between, and _add_days.  The _add_days will not work because this simply adds a day to the date selected. 

Still trying to find a feasible solution to this.

Offline Magdalina08

  • Full Member
  • ***
  • Join Date: Oct 2019
  • Posts: 7
  • Forum Citizenship: +0/-0
Re: Create Pop-up Warning or Restrict Date Prompt
« Reply #6 on: 11 Oct 2019 11:53:35 am »
math 101... if you add a negative number, it will actually result to subtraction.


Not sure I am following here.  This is the description from Cognos on the _add_days function:

_add_days ( date_expression, integer_expression )
Returns the date or datetime, depending on the format of "date_expression", that results from adding "integer_expression" days to "date_expression".

Example: _add_days ( 2002-04-30 , 1 )
Result: 2002-05-01

Example: _add_days ( 2002-04-30 12:10:10.000, 1 )
Result: 2002-05-01 12:10:10.000

Example: _add_days ( 2002-04-30 00:00:00.000, 1/24 )
Note that the second argument is not a whole number. This is supported by some database technologies and increments the time portion.
Result: 2002-04-30 01:00:00.000

Offline Francis aka khayman

  • Statesman
  • ******
  • Join Date: Jun 2009
  • Posts: 480
  • Forum Citizenship: +25/-3
    • CognosM
Re: Create Pop-up Warning or Restrict Date Prompt
« Reply #7 on: 11 Oct 2019 12:33:11 pm »
can you try what the result of this is?

_add_days(2002-04-30,-365)

** you may have to provide a correct date value

Offline Magdalina08

  • Full Member
  • ***
  • Join Date: Oct 2019
  • Posts: 7
  • Forum Citizenship: +0/-0
Re: Create Pop-up Warning or Restrict Date Prompt
« Reply #8 on: 11 Oct 2019 12:46:40 pm »
This just gave me a date that was 365 days less than my date.

(2019-01-01, -365) = 2018-01-01

Offline Francis aka khayman

  • Statesman
  • ******
  • Join Date: Jun 2009
  • Posts: 480
  • Forum Citizenship: +25/-3
    • CognosM
Re: Create Pop-up Warning or Restrict Date Prompt
« Reply #9 on: 11 Oct 2019 12:49:19 pm »
then can you not filter your data where [Date of my data] > _add_days([Start Date from Prompt],-365)

Offline dougp

  • Statesman
  • ******
  • Join Date: Jul 2014
  • Posts: 432
  • Forum Citizenship: +21/-1

Offline Magdalina08

  • Full Member
  • ***
  • Join Date: Oct 2019
  • Posts: 7
  • Forum Citizenship: +0/-0
Re: Create Pop-up Warning or Restrict Date Prompt
« Reply #11 on: 15 Oct 2019 10:50:53 am »
It looks like there is a sample that may be similar on the CA blog site.

https://community.ibm.com/community/user/businessanalytics/blogs/steven-macko/2018/09/10/javascript-samples-for-ibm-cognos-analytics?CommunityKey=6b10df83-0b3c-4f92-8b1f-1fd80d0e7e58&tab=recentcommunityblogsdashboard


That is super helpful for Cognos 11.  Do you know if this works in 10.2, if there is exisiting script for that version, or if this script will work? I haven't used JS in Cognos before, so this would be a first for me and I've read it's not very compatible in versions below 11.  We have version 11 so I was able to pull the files, but the client isn't ready to move that way yet. 

Offline Magdalina08

  • Full Member
  • ***
  • Join Date: Oct 2019
  • Posts: 7
  • Forum Citizenship: +0/-0
Re: Create Pop-up Warning or Restrict Date Prompt
« Reply #12 on: 15 Oct 2019 12:19:01 pm »
I did find this for version 10.2.  Trying to get the samples imported now and will inform how it goes.

https://www.ibm.com/support/knowledgecenter/SSEP7J_10.2.1/com.ibm.swg.ba.cognos.ug_cr_rptstd.10.2.1.1.doc/c_rs_smples_prompt_api.html

 



       
Twittear