Using a single Report Viewer for Multiple Reports

I have 5 reports that need to be able to be viewed from a single report viewer. I use this code in a button to select the report to be viewed
event.source.parent.getComponent('Report Viewer').reportPath = 'Path'

This works but each report has different parameters, so when i alternate the reports, the parameter binding (to tags) disappear. how can i programmatically set the report parameter binding with the button script?

You can’t. For any parameters that are different, you’ll have to script the update of those parameters. If there’s a collection of possible bindings with specific names, you could bind them all elsewhere, then use a propertyChange event on that other object to copy the values. Do it in a try…except construct to ignore any writes to the viewer when the specific property isn’t there.

This sounds like something that @pturmel helped me with a while ago. Thanks Phil!!

What I ended up with was the print preview popup window that I attached as a file below. It has a couple of custom properties and some scripting that you can investigate on. To view one of my reports, I have the following script in a button on the screen:

headers = ["StartSegment", "EndSegment", "suggestedFilename"]
data = []
data.append([event.source.parent.getComponent('Recipe List').StartSegmentSelected, event.source.parent.getComponent('Recipe List').EndSegmentSelected, "Furnace Recipe #" + str(event.source.parent.getComponent('Recipe List').StartSegmentSelected) + " "+ str(, "yyyy-MM-dd"))])
reportParameters = system.dataset.toDataSet(headers, data)

window = system.nav.openWindow('Popups/ReportPrintPreview', {'ReportPath' : 'Recipe Reports\Furnace Recipe Sheet', 'ReportParameters' : reportParameters})

Some of my other reports are called slightly differently. Those have a dataset already existing on the window the user is working in, and I just copy that dataset into the popup’s custom property instead of building the dataset in the script.

It’s worked pretty well for me. The only thing that I’ve had to pay attention to is that if I’m putting a parameter into the dataset, the report had better have that parameter configured, otherwise it will throw an error about a non-existent property when the script is trying to assign a value. I could probably wrap it in a try/except block, but then I’d spend more time scratching my head over misspellings between my report parameters and my dataset parameters :sweat_smile:

Hopefully something here is useful. :slight_smile:

Report Print Preview window.proj (26.7 KB)


That seems like a good option, but I found a more simple solution for my situation. I only have four reports, and 2 of them have several parameters that would need to be set. So I just stacked 4 report viewers on top of each other and used the buttons to set their visibility instead of using one viewer and changing the report path and parameters.

1 Like