Script error with system.alarm.queryStatus

I think I am having the same issue

alarmEvents = system.alarm.queryStatus(displaypath =[event.source.parent.getComponent('AlarmHi').toolTipText.replace("\"","") + "*",event.source.parent.getComponent('AlarmLo').toolTipText.replace("\"","") + "*",event.source.parent.getComponent('AlarmHiHi').toolTipText.replace("\"","") + "*",event.source.parent.getComponent('AlarmLoLo').toolTipText.replace("\"","") + "*"],state=["ActiveUnacked","ClearUnacked"])

This above line works in some places but not others.

I get an error

Traceback (most recent call last):
  File "<event:mouseReleased>", line 35, in AckAlarm
AttributeError: 'NoneType' object has no attribute 'replace'

	at org.python.core.Py.AttributeError(Py.java:207)
	at org.python.core.PyObject.noAttributeError(PyObject.java:1032)
	at org.python.core.PyObject.__getattr__(PyObject.java:1027)
	at org.python.pycode._pyx171.AckAlarm$1(<event:mouseReleased>:45)
	at org.python.pycode._pyx171.call_function(<event:mouseReleased>)
	at org.python.core.PyTableCode.call(PyTableCode.java:171)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:139)
	at org.python.core.PyFunction.__call__(PyFunction.java:413)
	at org.python.core.PyFunction.__call__(PyFunction.java:408)
	at com.inductiveautomation.factorypmi.application.script.builtin.WindowUtilities$JyPopupMenu.actionPerformed(WindowUtilities.java:911)
	at java.desktop/javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at java.desktop/javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at java.desktop/javax.swing.AbstractButton.doClick(Unknown Source)
	at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
	at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
	at java.desktop/java.awt.Component.processMouseEvent(Unknown Source)
	at java.desktop/javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.Component.processEvent(Unknown Source)
	at java.desktop/java.awt.Container.processEvent(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.Component.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.desktop/java.awt.EventQueue$5.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

Ignition v8.0.10 (b2020031912)
Java: Azul Systems, Inc. 11.0.6

The stacktrace is doing it’s best to tell you what’s wrong; one of the toolTipText properties is None, rather than an empty string, some of the time you’re calling your script. You could isolate your calls by spacing them out, which might help you get a more accurate line number for the error:

alarmEvents = system.alarm.queryStatus(
	displaypath =[event.source.parent.getComponent('AlarmHi').toolTipText.replace("\"","") + "*"
		, event.source.parent.getComponent('AlarmLo').toolTipText.replace("\"","") + "*"
		, event.source.parent.getComponent('AlarmHiHi').toolTipText.replace("\"","") + "*"
		, event.source.parent.getComponent('AlarmLoLo').toolTipText.replace("\"","") + "*"
	]
	, state=["ActiveUnacked","ClearUnacked"]
)

Or, you can break out the logic and more easily add a ‘safe’ substitution (Python’s None is a ‘false-ey’ value, and inline or will return the second value if the first is false):

def getFilter(component):
	return (event.source.parent.getComponent(component).toolTipText or "").replace('"', '') + '*'

components = ['AlarmHi', 'AlarmLo', 'AlarmHiHi', 'AlarmLoLo']

alarmEvents = system.alarm.queryStatus(displaypath =[getFilter(component) for component in components], state=["ActiveUnacked","ClearUnacked"])

Thanks Paul,

The second approach works.