You are not logged in.
Hi,
I am trying to import Jasper Report Schedulers into Report Server.
I have a number of schedulers for a Jasper report where each scheduler is providing different parameters, such as client IDs, to the same report and sent to different clients.
I understand that within Report Server, I would need to create a report and one variant per client where each variant would contain the parameters for each particular client. Then I would need to create one scheduler for each variant to send the reports to each client.
Using the scripting feature, I was able to create a report and a variant. However, I am struggling with setting the parameter to each variant as it seems the parameters are not persisted.
Could you provide guidance on how to correctly assign parameter values to a variant?
The code I used to unsuccessfully assign parameters to a variant is shown below
def reportParameterService = GLOBALS.getInstance(ReportParameterService);
def reportService = GLOBALS.getInstance(ReportService);
def report = reportService.getNodeByPath(reportUnitURI);
def variantReport = ((JasperReport)report).createNewVariant(report)
variantReport.setName(label);
for (item in parameterMap) {
def definition = variantReport.getParameterDefinitionByKey(item.key);
if (definition != null) {
def instance = variantReport.getParameterInstanceFor(definition);
if (definition.getMode() == Mode.Single) {
def parameter_value = item.value.get(0);
def instance_value = new DatasourceParameterData();
instance_value.setKey(parameter_value);
instance_value.setValue(parameter_value);
instance.setSingleValue(instance_value);
// Tried persisting the ParameterInstance, merging the ParameterDefinition and merging the ReportVariant with no success
reportParameterService.persist(instance);
reportParameterService.merge(definition);
reportService.merge(variantReport);
} else if (definition.getMode() == Mode.Multi) {
def instance_value_list = new ArrayList();
for (parameter_value in item.value) {
def instance_value = new DatasourceParameterData();
instance_value.setKey(parameter_value);
instance_value.setValue(parameter_value);
instance_value_list.add(instance_value);
}
instance.setMultiValue(instance_value_list);
// Tried persisting the ParameterInstance, merging the ParameterDefinition and merging the ReportVariant with no success
reportParameterService.persist(instance);
reportParameterService.merge(definition);
reportService.merge(variantReport);
}
}
}
Offline
Hey,
we need some more informations at this point to help you. Could you please provide the full script. Keep in mind, when executing the script in the terminal use "-c" to commit changes to the db, e.g. "exec -c example.groovy".
Offline
Hi André,
Thank you for your response.
I was able to fix this issue by calling the setStillDefault(false) method on the ParameterInstance object. This resulted in my changes being reflected in the UI.
Not sure what the stillDefault variable is for though
This is my final script for assigning parameters to Jasper report variants. Notice the call to setStillDefault method after either setting the single or multi value
def variantReport = ((JasperReport)report).createNewVariant(report)
variantReport.setName(label);
for (item in parameterMap) {
def definition = variantReport.getParameterDefinitionByKey(item.key);
if (definition != null) {
def instance = variantReport.getParameterInstanceFor(definition);
if (definition.getMode() == Mode.Single) {
def parameter_value = item.value.get(0);
def instance_value = new DatasourceParameterData();
instance_value.setKey(parameter_value);
instance_value.setValue(parameter_value);
instance.setSingleValue(instance_value);
instance.setStillDefault(false);
} else if (definition.getMode() == Mode.Multi) {
def instance_value_list = new ArrayList();
for (parameter_value in item.value) {
def instance_value = new DatasourceParameterData();
instance_value.setKey(parameter_value);
instance_value.setValue(parameter_value);
instance_value_list.add(instance_value);
}
instance.setMultiValue(instance_value_list);
instance.setStillDefault(false);
}
}
}
Thanks,
Offline
Hello,
the function sets a Boolean value that indicates whether the default values have been changed.
Best regards
Jasmin
Offline