Refresh table from [shared] Script Library or from tag change event

I have a shared script that finishes with a db update.

   system.db.runPrepUpdate(query,args,"IgnitionTables")

I’d like to add the following lines to refresh my ignition table’s values after updating my sql db.

window = system.gui.getWindow('Main window')
table = window.rootContainer.getComponent('Table 1')
system.db.refresh(table, 'data')

But I get an error that the object ‘gui’ is not found. I assume that my shared script simply doesn’t know what project to look in for the specified window. I also have tried adding a memory tag that I turn on when the shared script is finished (basically a handshake), and then adding a tag event script to it which would again include:

window = system.gui.getWindow('Main window')
table = window.rootContainer.getComponent('Table 1')
system.db.refresh(table, 'data')

but that also didn’t work. What is the best way to refresh my table each time my [shared] script finishes?

I think your tag handshake might work, but your issue is system.gui is only available within a Client scope, not from the Gateway where tag change event scripts run. Making your tag a client tag might help, but then you need to update each clients copy from the Gateway.

I think you should call your shared script from a Gateway Event Script, and when it’s finished you can send out a message to all clients using system.util.sendMessage. You’d then need a Client Message Handler to receive that message and update the table.

I attempted to write to a client tag from a [shared] script but was unsuccessful. I’ll try your suggestion of “system.util.sendMessage”. Thanks for the support.

this worked for me

project.projFuncs.refresh_all() # how to call this function

def refresh_all():
try:
window = system.gui.getWindow(‘Window_Name’)

	system.db.refresh(window.getRootContainer().getComponent('Table1'), 'data')
	system.db.refresh(window.getRootContainer().getComponent('Table2'), 'data')
	system.db.refresh(window.getRootContainer().getComponent('Field Intro'), 'data')
	
except ValueError:
   system.gui.warningBox("Failed to Open Barcode Recipes Window")

this interface mangled the formatting so you’ll have to adjust that

Well, it did the best it could without a hint about what is code and what is not. Place code markers by using the “Preformatted text” button while your code is highlighted. Or place three back-quotes (these ```) on a line above and again on a line below your code. It should look like this:

```
My pasted code
```