Trying to understand the 'system.gui.getWindow' method

Using vision, with designer version 8.1.21.

I have a form with a table on it that needs to have a new row of data added, as well as have the data inserted into the database that the table is displaying.

What I did was add a new popup that allows the user to enter the data. The popup is called when the user clicks a button. When the user is done entering the data, they click the 'Add' button on the popup (see the following script that gets run). Everything works as intended until it hits the getWindow method. For some reason, it seems to think that the window that called the popup isn't open. More about this below the script.

import java.lang.Exception
name = event.source.parent.getComponent('Text Field').text
email_address = event.source.parent.getComponent('Text Field 1').text
alarms = event.source.parent.getComponent('CheckBox').selected
informational = event.source.parent.getComponent('CheckBox 1').selected
agency_alerts = event.source.parent.getComponent('CheckBox 2').selected
monthly_reports = event.source.parent.getComponent('CheckBox 3').selected

query = "INSERT INTO `test`.`email_list` (`Name`, `email_address`, `Agency_Alerts`, `Alarms`, `Alerts`, `monthly_reports`) VALUES (?, ?, ?, ?, ?, ?)"
print query
try:
	system.db.runPrepUpdate(query, (name, email_address, agency_alerts, alarms, informational, monthly_reports ))
	print "query complete"
except java.lang.Exception, e:
	error_message = "SQL Error: "
	error_message += str(e.cause)
	Error_String = error_message.rpartition(':')[-1]
	system.gui.messageBox(Error_String)
	
#  Get the path back to the configuration window so we can trigger the db table update.
try:
	print "get the window"
	window = system.gui.getWindow("Configuration")
	print window
	print "get the table"
	table = window.rootContainer.Container.getComponent('Table')
	system.db.refresh(table, "data")

except Exception as e:
	#The Configuration Window isn't open, so we don't need to trigger the table update anyway
	Error_String = "error: " + str(e.message) 
	system.gui.messageBox(Error_String)
	pass
		
system.gui.closeParentWindow(event)

Here is the result. Notice that the 'Configuration' window is visible behind the popup and the message box with the error in it:

Here's a screen shot of the project browser to show the relative paths:

The 'Add email' popup window is where the script runs when the user clicks the 'Add' button. The 'Configuration' window is where the table is that I want to trigger the db update on.

I don't know if this is helpful or not, but here is the event that opens the popup when the user clicks the 'New' button on the Configuration form:

I'm wondering if I have to include something about the Main Window and/or the tabbed Navigation window to get the results I'm looking for?

I'm sure I've missed something simple (again!). Any helpful pointers would be appreciated.

Thanks!

You need the full window path ("Main Windows/Configuration"), not just "Configuration".

Many thanks (again!), Paul! That got me past a problem that I stared at for several hours and just couldn't figure out.

For my future self (and anyone else that might stumble across this post), there was one more problem with the script where I attempted to get the reference to the table that was in another container one level down.

I was able to figure that one out after reading this article. From that, the following line:

table = window.rootContainer.Container.getComponent('Table')

becomes this:

table = window.rootContainer.getComponent('Container').getComponent('Table')

With that, everything is working.

Again, many thanks!

1 Like