# Refreshing Report Viewer

**URL:** <https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [April 20, 2017, 9:31am UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089 "2017-04-20T09:31:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Smits](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@Tom\_Smits](https://forum.inductiveautomation.com/u/Tom_Smits)\
**Post date:** [April 20, 2017, 9:31am UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089/1 "2017-04-20T09:31:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [April 20, 2017, 11:49am UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089/2 "2017-04-20T11:49:38Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 20, 2017, 8:07pm UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089/3 "2017-04-20T20:07:21Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![Tom\_Smits](https://avatars.discourse-cdn.com/v4/letter/t/76d3ee/32.png) [@Tom\_Smits](https://forum.inductiveautomation.com/u/Tom_Smits)\
**Post date:** [April 21, 2017, 12:05pm UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089/4 "2017-04-21T12:05:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [September 6, 2017, 5:58pm UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089/5 "2017-09-06T17:58:09Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [September 6, 2017, 7:03pm UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089/6 "2017-09-06T19:03:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cbanzet](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cbanzet/32/6207_2.png) [@cbanzet](https://forum.inductiveautomation.com/u/cbanzet)\
**Post date:** [March 23, 2021, 6:41pm UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089/7 "2021-03-23T18:41:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![apurdy](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@apurdy](https://forum.inductiveautomation.com/u/apurdy)\
**Post date:** [March 26, 2021, 3:12pm UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089/8 "2021-03-26T15:12:30Z")

</div>

And 3/26/2021!!

---

<div class="post-metadata">

**Author:** ![vipo](https://avatars.discourse-cdn.com/v4/letter/v/eada6e/32.png) [@vipo](https://forum.inductiveautomation.com/u/vipo)\
**Post date:** [April 29, 2021, 11:10am UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089/9 "2021-04-29T11:10:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matabufalez](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matabufalez/32/42267_2.png) [@Matabufalez](https://forum.inductiveautomation.com/u/Matabufalez)\
**Post date:** [January 30, 2023, 12:50pm UTC](https://forum.inductiveautomation.com/t/refreshing-report-viewer/14089/10 "2023-01-30T12:50:52Z")

</div>

Sorry for updating old post, but... Even if the parameter is not used in the named query (but it is added to it), the report will be refreshed?
