Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Parameters dynamic on Scheduled Reports
Mima
<p>Hi,<br><br>
I have a report design with a dynamic Parameter for the Start date.<br><br>
BirtDateTime.firstDayOfMonth(BirtDateTime.addMonth(BirtDateTime.today(), -12))<br><br>
Now I want to schedule the job, always using this dynamic condition on the day when the report is executed.<br><br>
The Report is scheduled once a month, and shall show always 12 months starting from the day in the Start Date Parameter.<br><br>
When starting the schedule I realized, that the Job Scheduler is always using the Start Date as it was calculated when the job schedule was set up.<br><br>
Is there any possibility in the scheduler to dynamically change the Start Date every time the job scheduler is triggered?<br><br>
Many thanks for your help in advanced!<br><br>
Miriam<br>
</p>
Find more posts tagged with
Comments
micajblock
<p>Don't use a parameter but set the default value in the data set parameters themselves. Look at the attached design using Classic Models.</p>
Mima
<p>Hi,</p>
<p> </p>
<p>Many thanks for your fast reply!</p>
<p> </p>
<p>I was hoping for a different solution, as the Report is used manually as well as a scheduled Job.</p>
<p> </p>
<p>Anyway, done as recommended and working fine.</p>
<p> </p>
<p>Thanks</p>
<p> </p>
<p>Miriam Koepke</p>
micajblock
<p>You could have a hidden parameter for scheduled job and test for that.</p>
jfranken
<p>Mima,</p>
<p> </p>
<p>Create a new Report Parameter. Name it startDate. For the data type choose "date". Optionally enter a default value. Save the parameter.</p>
<p> </p>
<p>Create a second Report Parameter called "scheduled" also with data type date. Click the Hidden checkbox so that it will not display. In the Default Value box for the parameter, enter the code: BirtDateTime.today();</p>
<p>Save the parameter.</p>
<p> </p>
<p>Make sure the Report object is selected, then go to the Script tab and choose the beforeFactory event. In that event, enter the following code:</p>
<p> </p>
<p>If (params["scheduled"] != BirtDateTime.today()) {</p>
<p> params["startDate"] = BirtDateTime.firstDayOfMonth(BirtDateTime.addMonth(params["startDate"], -12));</p>
<p>}</p>
<p> </p>
<p>Note: I haven't tested this code although I have created reports that set the parameter value in beforeFactory so I know that works.</p>
<p> </p>
<p>Explanation: When you schedule a report to run on the server, there is a tab in the scheduler window called "Parameters" where you can enter parameter values manually. The report runs automatically after it has been scheduled, so there is only one chance to set the parameter values- at the time the job is scheduled. You can also set the default value of a parameter when you create it in the Designer, either setting it to a static value or using the expression builder to write code to set its value dynamically (as you have done). If you go to the Parameters tab when scheduling a job, you will see that your code to set the parameter value has already run. It has supplied the default value for the parameter that was generated via your code. That is the only time the code runs! The code to set the parameter value is "outside the loop" for the code that runs each time a scheduled report gets created. It runs once when you schedule the report.</p>
<p> </p>
<p>If you're wondering why the code to set the values of your parameters does not run each time a scheduled report is generated, I'm not certain. My guess is that since scheduled reports are run automatically and parameters offer the option to be manually set by the user, the functionality to set parameter values is only available at the time the report is scheduled to avoid situations where a required value must be manually supplied but the report is scheduled to be automatically generated at 3:00am each Saturday. Many errors would occur.</p>
<p> </p>
<p>Fortunately there is a simple solution to deal with parameters where the value needs to be set dynamically via code each time the report runs. Just put the code in an event that is triggered each time a scheduled report runs, an event that triggers before the data is retrieved. The beforeFactory event for the Report object is such an event. </p>
<p> </p>
<p>I added the hidden parameter called "scheduled" and included the "if" statement to check to see if the report is being run manually which you said is an option. If the report is run manually, your code that sets the start date back by 12 months will be ignored and the manually entered date will be used. If the report is a scheduled job, your code will be executed returning a new value each time the report is run. (The code to set the date for the hidden parameter called "scheduled" will run only once when the report is scheduled as I described above. Its value will not change. The today() call inside the "if" statement in the beforeFactory event will get the new date each time the report is run. Those two dates won't match for scheduled jobs and your code will run because the if statement checks for a != condition.)</p>
<p> </p>
<p>I hope this helps,</p>
<p>Jeff</p>
<p>Customer Support Engineer I</p>