Getting the Error Messages Dialog Text Through Script

Hello I’m trying to get the error messages from the dialog boxes through script to handle certain errors, but I can’t seem to find where the messages can be grabbed from

image

I’m using the code below to close open dialog boxes within the client, but I want to save the message somewhere. I’m trying to close them because they shouldn’t show up in client. The error and warning messages show up in output console, but I’m not sure how to reach that through script either

Example in output console
16:40:50.399 [AWT-EventQueue-0] ERROR com.inductiveautomation.factorypmi.application.script.builtin.WindowUtilities - Something
16:40:50.420 [AWT-EventQueue-0] WARN com.inductiveautomation.factorypmi.application.script.builtin.WindowUtilities - Something 21

"""
Description: 
The warning box in Ignition can be minimized and therefore not seen again.
To fix this, we will add a window listener that will intercept the minimize action 
and remaximize that said window
"""
from javax.swing import SwingUtilities
from java.awt.event import WindowAdapter
from javax.swing import JFrame
from com.inductiveautomation.factorypmi.application.script.builtin import WindowUtilities

class dialogBoxListener(WindowAdapter):
	def windowIconified(self,event):
		event.source.setState(JFrame.NORMAL)

#Create an instance of the warning box
#system.gui.warningBox("warning","Warning")
#system.gui.errorBox("Something", "Error")
#system.gui.errorBox("Something", "Error")

#Find the warning box
par = event.source
par = SwingUtilities.getRoot(par)
warnWindow = errWindow = None

system.gui.errorBox("Something")
system.gui.warningBox("Something 21")

#Grabing all the warning and error windows
try:
	getwindows = [w for w in par.getWindows()]
	warnWindow = [w for w in getwindows if "title=Warning" in str(w)][0]
	errWindow = [w for w in getwindows if "title=Error" in str(w)][0]
except:
	pass

#If there are warning windows, close them
if warnWindow!=None:
	print(warnWindow)
	warnWindow.addWindowListener(dialogBoxListener())
	warnWindow.center()
	warnWindow.close()

#If there are error windows, close them
if errWindow!=None:
	print(errWindow)
	errWindow.addWindowListener(dialogBoxListener())
	errWindow.center()
	errWindow.close()

Thank you!!

If you can surround the code that is throwing errors with a try/catch, you can get the message with:

try:
    #whatever is giving you the error
except Exception as e:
    print e

Somethimes e.message works better…

To save those messages, you could use getLogger:

logger = system.util.getLogger("windowErrors")
logger.info(e.message)

Quick scripting tip:

instead of building the whole list then taking the first item, you can use this:

warnWindow = next(w for w in getwindows if "title=Warning" in str(w))

This will raise StopIteration if the item is not found.
If you'd rather have a default value returned in case what you're looking for isn't found, next can take it as a parameter, for example with None:

warnWindow = next((w for w in getwindows if "title=Warning" in str(w)), None)

Note the added parentheses.

Why is it better than the [list comprehension][0] version ?
This way you don't actually build the list, as it's using a generator, and it will stop as soon as the item is found.

from com.inductiveautomation.ignition.client.util.gui import ErrorUtil
from org.apache.commons.lang3.reflect import FieldUtils

errorPanel = FieldUtils.readStaticField(ErrorUtil, "errorPanel", True)
warningPanel = FieldUtils.readStaticField(ErrorUtil, "warningPanel", True)
errors = FieldUtils.readField(errorPanel, "errors", True)
warnings = FieldUtils.readField(warningPanel, "errors", True)

for error in errors:
	print error.title
	print error.message
	print error.exception
	
for warning in warnings:
	print warning.title
	print warning.message
	print warning.exception

I’m trying to create a script for a delete button linked to a table. My second line reads as follows:

if len(selRows) > 0:

It keeps coming back as “mismatched input expecting eof”. Can someone explain to me what I’m doing wrong.

What does this have to do with this topic? You should start a new topic, show your code, and show the complete error you are getting.

This is exactly what I’m looking for
Thank you so much PGriffith!!