Refreshing Report Viewer

Hello there,

I’m currently working on a project where I have to generate a report every time a new record is inserted in my database.

So far, I have created a label which is filled with the highest “BalkID” in my database.
When this “BalkID” updates, the label updates instantly to the new maximum ID.

On the PropertyChange event of this label, I inserted the following script to save a report:

window = system.gui.getWindow(“Report”)
report = window.rootContainer.getComponent(“Report Viewer”)
balk = system.tag.read(“Querytags/Query/BalkID”).value
bytes = report.getBytesPDF()
filename = “C:\Users\Ignition\Desktop\%s.pdf” % balk
if filename != None:
system.file.writeFile(filename, bytes)

So, if the label value updates, the report in the report viewer is saved. This works fine, however, the data in my report is not refreshing. Only when I close and reopen the window “report”, the balkID in my report viewer is updated to the maximum value in my database.

How do I automatically refresh, execute or update the data in my report viewer when a new record is added in my database (or when the value of a label/tag changes)?

It sounds like your report doesn’t use parameters so refreshing those won’t work.
Have you tried setting the reportPath to ‘’ and then back to the actual report path?

event.source.parent.getComponent(‘Report Viewer’).reportPath=’’
event.source.parent.getComponent(‘Report Viewer’).reportPath=‘ActualReportPath’

Hi Tom, welcome to the forums!

Create a new parameter in your report. Then in the report viewer, bind that parameter to Querytags/Query/BalkID.

Regardless of whether or not the parameter is used in the report, it will still refresh if a parameter changes. :slight_smile:

Hey folks,

I used both way’s by running the following script under a client tag change event:

window = system.gui.getWindow(“Report”)
window.rootContainer.getComponent(‘Report Viewer’).reportPath=’’
window.rootContainer.getComponent(‘Report Viewer’).reportPath=‘Handlijn’
report = window.rootContainer.getComponent(“Report Viewer”)
balk = system.tag.read(“Querytags/Query/BalkID”).value
bytes = report.getBytesPDF()
filename = “C:\Users\Ignition\Desktop\%s.pdf” % balk
if filename != None:
def refresh(path = window.rootContainer.getComponent(‘Report Viewer’)):
import system
filename = “C:\Users\Ignition\Desktop\%s.pdf” % system.tag.read(“Querytags/Query/BalkID”).value
window = system.gui.getWindow(“Report”)
window.rootContainer.getComponent(‘Report Viewer’).reportPath=’’
window.rootContainer.getComponent(‘Report Viewer’).reportPath=‘Handlijn’
report = window.rootContainer.getComponent(“Report Viewer”)
bytes = report.getBytesPDF()
system.file.writeFile(filename, bytes)
system.gui.messageBox(“Report has been saved”)
system.util.invokeLater(refresh,5000)

By adding the invoke later function, a delay of 5 seconds is added.
I don’t really know why I have to run the same steps twice, but wen I deleted the upper part, the script didn’t work anymore.

However, thanks for helping me out!

will calling the loadReport() function cause the queries to refresh in a report?

event.source.parent.getComponent(‘Report Viewer’).loadReport()

1 Like

Easiest way is to just change one of the report parameters.
That will cause a refresh

2 Likes

Thank you. This answer is still helping me 3/23/2021!!

4 Likes

And 3/26/2021!!

You can call reload() from another component if you like.
Example Perspective 8.0.3 and up:
self.getSibling(“PDFViewer”).reload()