COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: roddawg on 23 Sep 2016 03:11:39 PM

Title: Changing Prompt (parameter) Values from null on Optional Parameters
Post by: roddawg on 23 Sep 2016 03:11:39 PM
So I wrote a report for a group of Schools within our district.  They now want to schedule this report to kick off every Monday to summarize the previous weeks data.  Great except they have to select their school, and pick a start date and end date via parameters.  Because they want to schedule this, my thought is Javascript wouldn't work because it's not running in a browser to assign the values.  So I'd like to make them optional and default the values to ?startdate? = currentdate-7 days and ?endate? = currentdate.  I'm not sure if I can assign values to the parameters at runtime via code.  Any suggestions except re-writing the entire report filters?
Title: Re: Changing Prompt (parameter) Values from null on Optional Parameters
Post by: sdf on 26 Sep 2016 03:15:59 AM
can't you create an event for this, select the particular parameter for the school and go with your plan to create the start date as the current date..etc..
Title: Re: Changing Prompt (parameter) Values from null on Optional Parameters
Post by: roddawg on 26 Sep 2016 09:42:26 AM
yes...the issue isn't triggering it.  It was trying to work around having to recode the filters in the reports.  Previously there was a mandatory parameter for start and end dates.  Events, as far as I know, don't allow you to set non-static parameter values. I needed current_date for the end date and current_date-7 for the start date.  If Cognos would get smart and allow formulas in the default value field it would make things MUCH easier in many respects!
Title: Re: Changing Prompt (parameter) Values from null on Optional Parameters
Post by: dax on 26 Sep 2016 07:11:50 PM
I don't know how you'd get around this without changing the report filters but if you're ok to to that then you can use a prompt macro to create a prompt that has a default value (and will allow the report to run by schedule).  This should hopefully get you started:

[Your Date Item] between
#prompt('startdate','string','_add_days (current_date,-7)')# and  #prompt('enddate','string','current_date')#

The prompt function in this case has 3 arguments:

- the prompt name e.g. startdate
- the date type.  I actually don't even think this matters as seems to work regardless of what i put
- the default value

The the third one is the important one - in this case the user can choose to enter a value for startdate and enddate (assuming that you have a prompt page).  If they don't, or the report is scheduled then it will use the function return values.

Does that help?
Dax