# Schedule a jasper report with dynamic parameters

**URL:** <https://forum.reportserver.net/t/schedule-a-jasper-report-with-dynamic-parameters/1748>\
**Category:** ReportServer (EN)\
**Created:** [May 29, 2024, 3:00am UTC](https://forum.reportserver.net/t/schedule-a-jasper-report-with-dynamic-parameters/1748 "2024-05-29T03:00:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sakunthala](https://forum.reportserver.net/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@sakunthala](https://forum.reportserver.net/u/sakunthala)\
**Post date:** [May 29, 2024, 3:00am UTC](https://forum.reportserver.net/t/schedule-a-jasper-report-with-dynamic-parameters/1748/1 "2024-05-29T03:00:58Z")

</div>

Hi,

I want to schedule a jasper report that has dynamic parameters use to filter dataset. I already created a groovy script to schedule report as local file system but I need to pass parameters to my report. Otherwise it generates an empty report. Please give me a solution for this. Thank you

Sakuntala

---

<div class="post-metadata">

**Author:** ![IF\_Adrian](https://forum.reportserver.net/letter_avatar_proxy/v4/letter/i/6f9a4e/32.png) [@IF\_Adrian](https://forum.reportserver.net/u/IF_Adrian)\
**Post date:** [May 29, 2024, 10:19am UTC](https://forum.reportserver.net/t/schedule-a-jasper-report-with-dynamic-parameters/1748/2 "2024-05-29T10:19:45Z")

</div>

Hello,

If you want to set parameters for your report you need to create a variant. The variant will save to assigned parameters. You will need to schedule the variant instead of the base report.

With regards,  
Adrian

---

<div class="post-metadata">

**Author:** ![sakunthala](https://forum.reportserver.net/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@sakunthala](https://forum.reportserver.net/u/sakunthala)\
**Post date:** [May 30, 2024, 5:08am UTC](https://forum.reportserver.net/t/schedule-a-jasper-report-with-dynamic-parameters/1748/3 "2024-05-30T05:08:47Z")

</div>

Hi Adrian,

Thank you for your reply. But can we create variants for Jasper reports? and how do we create variants dynamically by passing respective report parameter values using groovy script?

Regards,  
Sakuntala

---

<div class="post-metadata">

**Author:** ![IF\_Felix](https://forum.reportserver.net/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@IF\_Felix](https://forum.reportserver.net/u/IF_Felix)\
**Post date:** [June 3, 2024, 9:39am UTC](https://forum.reportserver.net/t/schedule-a-jasper-report-with-dynamic-parameters/1748/4 "2024-06-03T09:39:43Z")

</div>

Hi,

sure you can create variants in groovy scripts: [https://reportserver.net/api/latest/javadoc/net/datenwerke/rs/base/service/reportengines/jasper/entities/JasperReport.html](https://reportserver.net/api/latest/javadoc/net/datenwerke/rs/base/service/reportengines/jasper/entities/JasperReport.html) createNewVariant()  
as well as setParameterDefinitions() from your freshly created variant: [https://reportserver.net/api/latest/javadoc/net/datenwerke/rs/base/service/reportengines/jasper/entities/JasperReportVariant.html](https://reportserver.net/api/latest/javadoc/net/datenwerke/rs/base/service/reportengines/jasper/entities/JasperReportVariant.html)

If you want to persist your freshly created reports try using the ReportService ([https://reportserver.net/api/latest/javadoc/net/datenwerke/rs/core/service/reportmanager/ReportService.html](https://reportserver.net/api/latest/javadoc/net/datenwerke/rs/core/service/reportmanager/ReportService.html))

to execute your reports (base reports as well as report variants) you can use the [https://reportserver.net/api/latest/javadoc/net/datenwerke/rs/core/service/reportmanager/ReportExecutorService.html](https://reportserver.net/api/latest/javadoc/net/datenwerke/rs/core/service/reportmanager/ReportExecutorService.html) together with all parameters you need.

kind regards,

Felix

---

<div class="post-metadata">

**Author:** ![sakunthala](https://forum.reportserver.net/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@sakunthala](https://forum.reportserver.net/u/sakunthala)\
**Post date:** [June 5, 2024, 3:09am UTC](https://forum.reportserver.net/t/schedule-a-jasper-report-with-dynamic-parameters/1748/5 "2024-06-05T03:09:59Z")

</div>

hi Felix,  
Thank you for answering my question, I created a variant and set parameters. then I am going to schedule my variant report. but I’m getting this error when execute the groovy script. appreciate if you can provide solution for this. Thank you

com.google.inject.ProvisionException: Unable to provision, see the following errors:

1. [Guice/ErrorInjectingMethod]: IllegalStateException: TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : ReportExecuteJob.report → Report  
at DwLoggedEvent.setAuthenticatorServiceProvider(DwLoggedEvent.java:40)  
while locating ScriptExecutionFailedEvent

Learn more:  
[https://github.com/google/guice/wiki/ERROR\_INJECTING\_METHOD](https://github.com/google/guice/wiki/ERROR_INJECTING_METHOD)

1 error

# ====================== Full classname legend:

# DwLoggedEvent: “net.datenwerke.security.service.eventlogger.DwLoggedEvent” Report: “net.datenwerke.rs.core.service.reportmanager.entities.reports.Report” ReportExecuteJob: “net.datenwerke.rs.scheduler.service.scheduler.jobs.report.ReportExecuteJob” ScriptExecutionFailedEvent: “net.datenwerke.rs.scripting.service.scripting.events.ScriptExecutionFailedEvent” TransientPropertyValueException: “org.hibernate.TransientPropertyValueException”

# End of classname legend:

at com.google.inject.internal.InternalProvisionException.toProvisionException(InternalProvisionException.java:251)  
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:74)  
at com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:1062)  
at net.datenwerke.rs.utils.eventbus.EventBusImpl.fireEvent(EventBusImpl.java:76)  
at net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:284)  
at net.datenwerke.rsenterprise.license.service.EnterpriseCheckInterceptor.invoke(EnterpriseCheckInterceptor.java:40)  
at net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:335)  
at net.datenwerke.rsenterprise.license.service.EnterpriseCheckInterceptor.invoke(EnterpriseCheckInterceptor.java:40)  
at net.datenwerke.rs.scripting.service.scripting.ScriptingServiceImpl.executeScript(ScriptingServiceImpl.java:307)  
at net.datenwerke.rsenterprise.license.service.EnterpriseCheckInterceptor.invoke(EnterpriseCheckInterceptor.java:40)  
at net.datenwerke.rs.scripting.service.scripting.terminal.commands.ExecScriptCommand.doRollbackExecute(ExecScriptCommand.java:354)  
at com.google.inject.persist.jpa.JpaLocalTxnInterceptor.invoke(JpaLocalTxnInterceptor.java:64)  
at net.datenwerke.rs.scripting.service.scripting.terminal.commands.ExecScriptCommand$1$1.doFilter(ExecScriptCommand.java:292)  
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:89)  
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:121)  
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:133)  
at net.datenwerke.rs.scripting.service.scripting.terminal.commands.ExecScriptCommand$1.call(ExecScriptCommand.java:284)  
at net.datenwerke.rs.scripting.service.scripting.terminal.commands.ExecScriptCommand$1.call(ExecScriptCommand.java:1)  
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)  
at java.base/java.lang.Thread.run(Thread.java:833)  
Caused by: java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : net.datenwerke.rs.scheduler.service.scheduler.jobs.report.ReportExecuteJob.report → net.datenwerke.rs.core.service.reportmanager.entities.reports.Report  
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:151)  
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1626)  
at org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(AbstractProducedQuery.java:1665)  
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getSingleResult(CriteriaQueryTypeQueryAdapter.java:111)  
at net.datenwerke.rs.utils.simplequery.byid.QueryByIdProcessor.process(QueryByIdProcessor.java:66)  
at net.datenwerke.rs.utils.simplequery.byid.QueryByIdInterceptor.invoke(QueryByIdInterceptor.java:24)  
at net.datenwerke.security.service.authenticator.RequestUserCacheImpl.getUser(RequestUserCacheImpl.java:28)  
at net.datenwerke.security.service.authenticator.AuthenticatorServiceImpl.getCurrentUser(AuthenticatorServiceImpl.java:180)  
at net.datenwerke.security.service.eventlogger.DwLoggedEvent.setAuthenticatorServiceProvider(DwLoggedEvent.java:41)  
at net.datenwerke.security.service.eventlogger.DwLoggedEvent$$FastClassByGuice$$1816581553.GUICE$TRAMPOLINE()  
at net.datenwerke.security.service.eventlogger.DwLoggedEvent$$FastClassByGuice$$1816581553.apply()  
at com.google.inject.internal.SingleMethodInjector$1.invoke(SingleMethodInjector.java:50)  
at com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector.java:87)  
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:146)  
at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:101)  
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:72)  
… 18 more  
Caused by: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : net.datenwerke.rs.scheduler.service.scheduler.jobs.report.ReportExecuteJob.report → net.datenwerke.rs.core.service.reportmanager.entities.reports.Report  
at org.hibernate.engine.spi.CascadingActions$8.noCascade(CascadingActions.java:379)  
at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:169)  
at org.hibernate.event.internal.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:159)  
at org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:149)  
at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:82)  
at org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:50)  
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:107)  
at org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1372)  
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1452)  
at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1649)  
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1617)  
… 32 more

---

<div class="post-metadata">

**Author:** ![IF\_Felix](https://forum.reportserver.net/letter_avatar_proxy/v4/letter/i/919ad9/32.png) [@IF\_Felix](https://forum.reportserver.net/u/IF_Felix)\
**Post date:** [June 5, 2024, 6:59am UTC](https://forum.reportserver.net/t/schedule-a-jasper-report-with-dynamic-parameters/1748/6 "2024-06-05T06:59:20Z")

</div>

Hi,  
This looks interesting and is definately not expected 😉  
while I am taking this error to my fellow developers… can you provide us your script ?

kind regards

felix

---

<div class="post-metadata">

**Author:** ![sakunthala](https://forum.reportserver.net/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@sakunthala](https://forum.reportserver.net/u/sakunthala)\
**Post date:** [June 5, 2024, 8:32am UTC](https://forum.reportserver.net/t/schedule-a-jasper-report-with-dynamic-parameters/1748/7 "2024-06-05T08:32:42Z")

</div>

hi Felix, we have solved the issue. Thank you  
This is my groovy code

import net.datenwerke.security.service.usermanager.UserManagerService  
import net.datenwerke.rs.core.service.reportmanager.ReportService  
import net.datenwerke.rs.scheduler.service.scheduler.jobs.report.ReportExecuteJob  
import net.datenwerke.rs.core.service.reportmanager.ReportExecutorService  
import net.datenwerke.rs.core.service.datasinkmanager.DatasinkTreeService  
import net.datenwerke.rs.core.service.datasinkmanager.DatasinkService  
import net.datenwerke.scheduler.service.scheduler.nlp.NlpTriggerService  
import net.datenwerke.scheduler.service.scheduler.SchedulerService  
import net.datenwerke.rs.localfsdatasink.service.localfsdatasink.LocalFileSystemService  
import net.datenwerke.rs.localfsdatasink.service.localfsdatasink.action.ScheduleAsLocalFileSystemFileAction  
import net.datenwerke.rs.base.service.reportengines.jasper.entities.JasperReport  
import net.datenwerke.rs.base.service.parameters.string.TextParameterInstance  
import net.datenwerke.rs.core.service.parameters.entities.ParameterInstance  
import java.util.logging.Level  
import java.util.logging.Logger

OWNER\_ID = 6L // the ID of the Owner  
EXECUTOR\_ID = 6L // the ID of the Executor  
RECIPIENT\_IDS = [6L] // the IDs of the Recipients  
OUTPUT\_FORMAT = ReportExecutorService.OUTPUT\_FORMAT\_PDF  
String localFolderPath = ‘./’  
JOB\_NAME = ‘Scheduling Job’  
JOB\_DESCRIPTION = ‘Report Scheduling Job’  
LOCAL\_DATASINK = ‘LocalFolder’

def userManagerService = GLOBALS.getRsService(UserManagerService)  
def reportService = GLOBALS.getInstance(ReportService)  
def datasinkTreeService = GLOBALS.getInstance(DatasinkTreeService)  
def triggerService = GLOBALS.getInstance(NlpTriggerService)  
def schedulerService = GLOBALS.getInstance(SchedulerService)  
def datasinkService = GLOBALS.getInstance(DatasinkService)  
def localfileSystemService=GLOBALS.getInstance(LocalFileSystemService)

def reportId = args[0].toInteger()//variant id  
def report = reportService.getReportById(reportId) // get Report by ID  
def owner = userManagerService.getNodeById(OWNER\_ID)  
def executor = userManagerService.getNodeById(EXECUTOR\_ID)  
def recipients = userManagerService.getUsers(RECIPIENT\_IDS)  
def reportName =report.getName()+‘-’+args[2].toString()

/\* create new variant of the report \*/

def variantRpt = ((JasperReport)report).createNewVariant(report)

variantRpt.setName(reportName)  
variantRpt.setKey(args[3].toString())

for (ParameterInstance instance : variantRpt.getParameterInstances()) {  
((TextParameterInstance)instance).setValue(args[3].toString())  
}

/\* create the Report Job and add the corresponding owner, executor and recipients \*/  
def job = new ReportExecuteJob(report: variantRpt, owners: [owner] ,executor: executor, recipients: recipients as List, outputFormat: OUTPUT\_FORMAT)

/\* Schedule as Local File System File Action \*/  
def localFileDatasink = datasinkTreeService.getDatasinkByName(LOCAL\_DATASINK)  
def action = new ScheduleAsLocalFileSystemFileAction(localFileSystemDatasink: localFileDatasink, name: reportName,folder: localFolderPath)

/\* add the description, version, actions etc. \*/  
job.title = JOB\_NAME  
job.description = JOB\_DESCRIPTION  
job.actions = [action]

```
/* parse the date with nlp */

```

def dateExpression = args[1]  
def trigger = triggerService.parseExpression dateExpression //DATE\_EXPRESSION

/\* schedule the job via the schedulerService \*/  
schedulerService.schedule job, trigger

/\* Logs \*/  
tout.println('Job: '+job)  
def prefix = “logger.groovy”  
def logger = Logger.getLogger(getClass().name)  
logger.log(Level.INFO, “$prefix INFO-level message $job”)

---

<div class="post-metadata">

**Author:** ![IF\_Eduardo](https://forum.reportserver.net/letter_avatar_proxy/v4/letter/i/94ad74/32.png) [@IF\_Eduardo](https://forum.reportserver.net/u/IF_Eduardo)\
**Post date:** [June 20, 2024, 11:52am UTC](https://forum.reportserver.net/t/schedule-a-jasper-report-with-dynamic-parameters/1748/8 "2024-06-20T11:52:29Z")

</div>

Hi sakunthala,

you don’t have to create the variant dynamically. You can create the variant statically in ReportServer, and then you can schedule this statically created variant in a script, analogous as here: [https://github.com/infofabrik/reportserver-samples/blob/main/src/net/datenwerke/rs/samples/maintenance/variantScheduler.groovy](https://github.com/infofabrik/reportserver-samples/blob/main/src/net/datenwerke/rs/samples/maintenance/variantScheduler.groovy)

In the script, you can set your parameters on the variant you already created.

Regards,  
Eduardo
