Portlight Posted April 26, 2011 Share Posted April 26, 2011 Is there a way to set the default date in jasperServer to 'today' for both the enddate and startdatecurrently we have it set for 1940 would like to change the default setting to be more dynamic Link to comment Share on other sites More sharing options...
mgeise Posted April 26, 2011 Share Posted April 26, 2011 Is this for a scheduled report or just running any report? If you set the defaultExpression for the parameter to new Date() this will set the current date. Link to comment Share on other sites More sharing options...
Portlight Posted April 27, 2011 Author Share Posted April 27, 2011 yes this is for scheduling I have the startdate parameter set in jasperserver - however it will only let me set it to an actual date. I would like it to set to new date() but it gives me an errorcould you be a little more specific please Link to comment Share on other sites More sharing options...
mgeise Posted April 27, 2011 Share Posted April 27, 2011 There are a couple of options that I would suggest:1) Within your start/ed date parameter(s), assuming that your parameter has a class of java.util.Date, enter new Date() as the default value expression and then when you deploy the report to JasperReport Server, don't add an input control for that parameter. Without the input control, it will always evaluate the default expression at runtime and use the current date.2) A more elegant way would be to create another parameter that takes a string to represent the date - i.e., it could take TODAY, YESTERDAY, TOMORROW, BEGINNING OF THIS MONTH, etc. - in addition to the actual date parameters. When deploying to JasperReport Server you could then create a single select list of values input control for the string parameter with the possible values of TODAY, etc. but you would not have input controls for the actual dates. Instead, you would use the string parameter to calculate the date using your own methods/class within the default Value Expression of the date parameters by setting the Default Expression to MyClass.calculateDate($P{StringParam}).For example, you might have a class MyClass and a static method calculateDate(String str). This class would be deployed with the report and the method would look something like the psuedo code beow.By doing this, you can set the String parameter to a constant value when you schedule the report and allow the report itself to calculate the actual dates relative to the actual run date/time at the time the report is running.Code:public static Date calculateDate(String str){ Date myDate = new Date(); if (str.equals("TODAY")) { myDate= new Date(); } elseif (str.equals("TODAY")) { myDate = /*calculate the beginning of the current month */}... return myDate;} Link to comment Share on other sites More sharing options...
mgeise Posted April 27, 2011 Share Posted April 27, 2011 Whoops...the last elseif should have a string of "BEGINNING OF THIS MONTH", not "TODAY". Link to comment Share on other sites More sharing options...
Portlight Posted April 27, 2011 Author Share Posted April 27, 2011 Thank you for the input! I actually have a param labaled autoDate - which passes as string to the stored procedure which calculates the date based on what is passed...I am not sure the reason my employer is requesting the startDate parameter in the actual server respository to be set to today by default. This would be something that would be server wide so not actually set in the reports. What I have is this:we do our reports in iReport - each report has a paramater called startDate - the value is new java.sql.Timestamp(0)however when we import the jrxml to the JasperServer and I attach the input parameter startDate - it defaults to a date that seems to be pre-set....how do i change that preset to be today.I am sure you have answered it and I am missing it, again thank you for helping me. Link to comment Share on other sites More sharing options...
mgeise Posted April 27, 2011 Share Posted April 27, 2011 change new java.sql.Timestamp(0) to new java.sql.Timestamp(new java.util.Date().getTime())...by having the 0 in there, you are setting it to the beginning of epoc time Link to comment Share on other sites More sharing options...
Portlight Posted April 28, 2011 Author Share Posted April 28, 2011 That is exactly what I needed! Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now