#1 2024-05-29 03:00:58

sakunthala
Member
Registered: 2024-04-17

Schedule a jasper report with dynamic parameters

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

Offline

#2 2024-05-29 10:19:45

adrian1703
Moderator
Registered: 2021-10-29

Re: Schedule a jasper report with dynamic parameters

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

Offline

#3 2024-05-30 05:08:47

sakunthala
Member
Registered: 2024-04-17

Re: Schedule a jasper report with dynamic parameters

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

Offline

#4 2024-06-03 09:39:43

Felix
Moderator
Registered: 2022-08-01

Re: Schedule a jasper report with dynamic parameters

Hi,

sure you can create variants in groovy scripts: https://reportserver.net/api/latest/jav … eport.html createNewVariant()
as well as setParameterDefinitions() from your freshly created variant: https://reportserver.net/api/latest/jav … riant.html

If you want to persist your freshly created reports try using the ReportService (https://reportserver.net/api/latest/jav … rvice.html)

to execute your reports (base reports as well as report variants) you can use the https://reportserver.net/api/latest/jav … rvice.html together with all parameters you need.

kind regards,

Felix


Softwareentwickler bei Infofabrik

Offline

#5 2024-06-05 03:09:59

sakunthala
Member
Registered: 2024-04-17

Re: Schedule a jasper report with dynamic parameters

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/ER … ING_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(<generated>)
   at net.datenwerke.security.service.eventlogger.DwLoggedEvent$$FastClassByGuice$$1816581553.apply(<generated>)
   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

Last edited by sakunthala (2024-06-05 06:10:23)

Offline

#6 2024-06-05 06:59:20

Felix
Moderator
Registered: 2022-08-01

Re: Schedule a jasper report with dynamic parameters

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

kind regards

felix


Softwareentwickler bei Infofabrik

Offline

#7 2024-06-05 08:32:42

sakunthala
Member
Registered: 2024-04-17

Re: Schedule a jasper report with dynamic parameters

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")

Last edited by sakunthala (2024-06-14 06:08:40)

Offline

#8 2024-06-20 11:52:29

eduardo
Administrator
Registered: 2016-11-01
Website

Re: Schedule a jasper report with dynamic parameters

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/reportser … ler.groovy

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

Regards,
Eduardo

Offline

Board footer

Powered by FluxBB