Perspective - Use tag to open popup

Hello,

I want to show a popup when one of my tag is true.

I've tried binding the tag to ta custom property in a view screen and then do a under a change script: I added just: system.perspective.openpop(viewpath). By doing so, when I turn on the bool, I got an error.

I would appreciate any feedback you guys have.

I also try adding this to the tag:

popupId = "checklist123456"
viewPath = "Popup/Checklist"  # insert your view path here
logger = system.util.getLogger("POPUP")
sessions = system.perspective.getSessionInfo()
for session in sessions:
    for pageId in session.pageIds:
        logger.info("{0} | {1}".format(session.id, pageId))
        if session.userAgent != "<designer>":
            if currentValue.value:
                system.perspective.openPopup(popupId, viewPath, sessionId=session.id, pageId=pageId)
            else:
                # note no viewPath arg
                system.perspective.closePopup(popupId, sessionId=session.id, pageId=pageId)

This works but it requires the user to have gateway homepage browser to be on in the background and the designer.

What is the error?

Don't do this. Your first instinct was correct.

Error is:

Error running property change script on view.custom.OpenPopup: Traceback (most recent call last): File "function:valueChanged", line 3, in valueChanged at com.inductiveautomation.perspective.gateway.script.PerspectiveScriptingFunctions.openPopup(PerspectiveScriptingFunctions.java:238) at jdk.internal.reflect.GeneratedMethodAccessor57.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: 'view' argument must be provided.

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "function:valueChanged", line 2, in valueChanged
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: 'view' argument must be provided.

caused by org.python.core.PyException

Traceback (most recent call last):
File "function:valueChanged", line 2, in valueChanged
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: 'view' argument must be provided.

caused by IllegalArgumentException: 'view' argument must be provided.

Ignition v8.1.33 (b2023101913)
Java: Azul Systems, Inc. 17.0.8

I get the gist; can you post the exact script you had in the property change script on the session custom property?

Post the error as preformatted text to make it easier to read, please see Wiki - how to post code on this forum.

You need to bind the tag you want to watch/trigger the popup to a custom property on either your perspective session or view, and then use a value changed script on that property to open the popup.

If you bind on the session property, you'll need to use a message handler to send an open window message to the currently open view, which will need to have the associated message handler defined.

sure. It just this:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
system.perspective.openPopup("Popup/Checklist")

I didn't want go further if this doesn't work.

Please put all code as formatted text so it's easier to read/retains indentation.

You are not providing the required arguments to system.perspective.openPopup.

You need to supply a popup Id as well as the path to the popup view.

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if (not previousValue or not previousValue.value) and currentValue.value:
		system.perspective.openPopup("_pChecklist", "Popup/Checklist")
1 Like

Thanks Mate. Got it to open the popup. How about when the tag goes to false and close out the popup? I tried the else statement but that doesn't seem to work.

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	if (not previousValue or not previousValue.value) and currentValue.value:
		system.perspective.openPopup("_pChecklist", "Popup/Checklist")
	
	elif (not previousValue or previousValue.value) and not currentValue.value:
		system.perspective.closePopup("_pChecklist")

Thanks Mate!