COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: M on 26 Feb 2016 07:00:24 AM

Title: Date picker on the report page
Post by: M on 26 Feb 2016 07:00:24 AM
Good day guys,

Stuck with an date prompt issue.

User wants a report to fecth previous day data and wants a date picker on the report page for reprompt.

I couldn't figure out the filter. When i run the report, it choose the current date as default date and displays nothing. Reprompt is working fine on the report page.

Please assist me guys

Thanks guys
Title: Re: Date picker on the report page
Post by: BigChris on 26 Feb 2016 07:49:19 AM
Hi - you might be able to do something with this:
http://cognostips.weebly.com/blog/date-prompts (http://cognostips.weebly.com/blog/date-prompts)
Title: Re: Date picker on the report page
Post by: M on 29 Feb 2016 05:01:55 AM
Thanks for the reply bigChris.

Sorry,i didn't explain the issue clearly.

When user run the report,

1, User want to see the report page directly with the yesterday's data.
2, User also wants a date prompt in the report page for reprompting with different date.

Thanks

Title: Re: Date picker on the report page
Post by: BigChris on 29 Feb 2016 05:32:35 AM
Yep, so you could build that prompt into the report page and default the selection
Title: Re: Date picker on the report page
Post by: M on 29 Feb 2016 07:32:16 AM

I created a prompt page in the report page. I couldn't pass the yesterday date to the date prompt.

I used a java script, but it can only change the date prompt to highlight the yesterdays date.

Title: Re: Date picker on the report page
Post by: R Ambre on 01 Mar 2016 07:49:45 AM
Hi,

To submit report directly for yesterday's date you can follow below solution.

1. Create one query "Query1"
2. Add data item "yesterday" with expression _add_days (current_date,-1)
3.Create prompt page
4. Add value prompt (name = startdate) on the prompt page with parameter name "p_date"
5. Assign "Query1" to value prompt and set  "yesterday" data item to use value.
6. Set visible property of Value prompt to "No"
7. Add JavaScript after value prompt with below expression

----------
<div id="msgDiv" style="color:chocolate; font-size:18"></div>
<script>
// Attach functions to an arbitrarily named object to mimic a namespace to ensure the name uniqueness
var zxcv = {};

// Get the required prompt.
var oCR = cognos.Report.getReport("_THIS_");
var oP = oCR.prompt.getControlByName("startdate");

// Get the values and isolate the first value.
var allValues = oP.getValues(true);
var firstValue = allValues[2];

// Set the prompt selection to the first value.
oValues = [firstValue];
oP.setValues(oValues);



setTimeout('oCVRS.promptAction(\'finish\')', 100);

// Display a debug message to indicate that this script has been run.
</script>
----------------------

8. Now you can use p_date parameter in your query. Report will default run for yesterday's date.
9.Now to have user to select date , add date prompt on  report page with same parameter "p_date"

I have tried this solution and it is working fine for me.

please let me know if you face any issues.
Title: Re: Date picker on the report page
Post by: M on 02 Mar 2016 08:51:16 AM

Thanks R Ambre.

I tried it and it doesn't filter on the yesterday date. I got all the data from DB.Page also refresh every second and page goes blank.







Title: Re: Date picker on the report page
Post by: R Ambre on 03 Mar 2016 03:15:12 AM
Hi
I tried this solution at my end and it is working fine.

Are you putting javascript on Prompt page ?
If it is on prompt page then page will not refresh again and again.

Are you applying p_date filter in your main query..if yes then it should show data only for selected date not for all dates from DB.

Please find attached screenshot of my report .
Title: Re: Date picker on the report page
Post by: R Ambre on 03 Mar 2016 03:17:05 AM
Forgot to mention.

Please use
setTimeout('promptAction(\'finish\')', 100); instead of
setTimeout('oCVRS.promptAction(\'finish\')', 100);
Title: Re: Date picker on the report page
Post by: Gopinath on 03 Mar 2016 03:48:07 AM
Hi,

Try using prompt macro in query filter

[Date Field] = #prompt('Promptparameter', 'date', '_add_days({sysdate}, -1)')#


The macro will return currentdate -1 when the report is first run.

Thanks,
Gopinath.M
Title: Re: Date picker on the report page
Post by: M on 04 Mar 2016 06:02:15 AM


Thanks Guys.

I don't know where am i going wrong . Its no working on my end.

R Ambre : Could you please send me the XML of your sample report?
Title: Re: Date picker on the report page
Post by: R Ambre on 04 Mar 2016 06:07:36 AM
Hi,

Please check attached XML
Title: Re: Date picker on the report page
Post by: navissar on 04 Mar 2016 10:25:30 AM
All the suggestions here are great. I personally would try to avoid the javascript one - you'll have to maintain it, and there's a way without it. The macro solution is good but you may experience formatting issues. They can be solved, of course. Have you tried the macro solution? What was the outcome?
Title: Re: Date picker on the report page
Post by: M on 08 Mar 2016 07:16:43 AM

Thanks R Ambre. It's working now.

I haven't  tried the macro solution. Will try and update .