system.perspective.openPopup, sessionId Optional but puts logs and error

Ignition version 8.1.24

system.perspective.openPopup - Ignition User Manual 8.1 - Ignition Documentation

The instructions say the sessionId parameter is optional.

String sessionId - Identifier of the Session to target. If omitted, the current Session will be used automatically. [optional]

I executed

system.perspective.openPopup("Test Popup", 'Test/Popup', showCloseIcon = True)

The popup doesn't appear and the logs have a dispatcher error:

Error executing tag event script: Traceback (most recent call last): File "<tagevent:valueChanged>", line 23, in valueChanged at
com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.getSession(AbstractScriptingFunctions.java:104) at
com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnSession(AbstractScriptingFunctions.java:118) at
com.inductiveautomation.perspective.gateway.script.AbstractScriptingFunctions.operateOnPage(AbstractScriptingFunctions.java:47) at
com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.popupAction(PerspectiveScriptingFunctions.java:758) at
com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.openPopup(PerspectiveScriptingFunctions.java:240) at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.IllegalArgumentException: java.lang.IllegalArgumentException:

No perspective session attached to this thread.

Are the instructions out of date?

Thanks,
Ted.

The location you're invoking the script from does not have insight into which Perspective Page is invoking the function. This error is typically seen when using openPopup() within Session Events, change scripts of session properties, and Tag change scripts. These areas are not of the "Page" context, and so the invocation has no idea what page to target/use.

The sessionId and pageId arguments are optional because if omitted they default to the current page. When not running from a Page context, they are no longer optional and you MUST provide the pageId you want to target; this informs the back-end which Page thread to utilize. I do not remember if sessionId is also required in this same scenario.

Ah, that makes sense, thanks @cmallonee.
I found Show a popup in perspective on all clients if a value changes - #30 by jlandwerlen and will dive into it.

This works.

popupId = "Test Popup"
		viewPath = "Test/Ted/Test Automatic Popup"
		logger = system.util.getLogger("Test Popup")
		logger.info("Testing popups.")
		sessions = system.perspective.getSessionInfo(projectFilter="ProjectX")
		for session in sessions:
			for pageId in session.pageIds:
				# logger.info("{0} | {1}".format(session.id, pageId))
				if currentValue.value:
					try:
						## Wrapped with 'try' because some sessions info productes errors:
						##     - java.lang.IllegalArgumentException: Invalid UUID string: 066328F8
						system.perspective.openPopup(popupId, viewPath, sessionId=session.id, pageId=pageId)
					except:
						logger.info("system.perspective.openPopup failed:  " + "{0} | {1}".format(session.id, pageId))
				else:
					try:
						## Wrapped with 'try' just incase it produces errors.
						system.perspective.closePopup(popupId, sessionId=session.id, pageId=pageId)
					except:
						logger.info("system.perspective.closePopup failed:  " + "{0} | {1}".format(session.id, pageId))
1 Like