Open pop up with tag event script ( Valued change)

Based on this link Open popup from session event - Ignition - Inductive Automation Forum, I’ve developed a message handler with script named downtimepopup:
system.perspective.openPopup('myPopupId', 'Primary/Downtime', position = {'left':100,'top':100},params=payload)

Then, a value change tag event script:

if previousValue.value == False and initialChange == False :
		system.perspective.sendMessage("downtimepopup")

But it doesn’t work, no error for tag diagnostics. Any suggestions would be appreciated!

I’m betting your Gateway logs would display some errors because tags have no way to access the page or session context that perspective call would need. You should look into using system.util.sendMessage() in the tag change event (make sure you specify the scope as “s” or “S” or whatever it expects), and then you’ll need a session event listener which will pipe the call into the session by using system.perspective.sendMessage().

2 Likes

so this is my value changed:

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	"""
	Fired whenever the current value changes in value or quality.

	Arguments:
		tag: The source tag object. A read-only wrapper for obtaining tag
		     properties.
		tagPath: The full path to the tag (String)
		previousValue: The previous value. This is a "qualified value", so it
		               has value, quality, and timestamp properties.
		currentValue: The current value. This is a "qualified value", so it has
		              value, quality, and timestamp properties.
		initialChange: A boolean flag indicating whether this event is due to
		               the first execution or initial subscription.
		missedEvents: A flag indicating that some events have been skipped due
		              to event overflow.
	"""
	if previousValue.value == False and initialChange == False :
		system.util.sendMessage(project="operators",messageHandler="popup_sessionevent",scope="S")

my session event listener named popup_sessionevent

`

def handleMessage(session, payload):
	"""
	This message handler will be called each time a message of this
	type is received.

	Arguments:
		session: The perspective session that is handling this
		         message
		payload: A dictionary that holds the objects passed to this
		         message handler. Retrieve them with a subscript, e.g.
		         myObject = payload['argumentName']
	"""
	system.perspective.sendMessage("downtimepopup",scope="session")`

my button message handler named downtimepopup
`

def onMessageReceived(self, payload):
	"""
	This method will be called when a message with the matching type code
	arrives at this component.

	Arguments:
		self: A reference to this component
		payload: The data object sent along with the message
	"""
	system.perspective.openPopup('97oSJOmz', 'Primary/Downtime')

`

Having ScriptRunner error in gateway log. Could be my syntax ?

Edit: Here is the full solution!

Maybe, what’s the error?
Also, your session event handler needs to specify a scope of session:

system.perspective.sendMessage("downtimepopup", scope="session")

This could be the cause of your error because the default scope is “page”. Since there is not page context within the session event script that could be your problem.

I also noticed an extraneous tick mark in your session event listener (look at the end of the code there).

1 Like

You are my life saver! It works! Appreciate your support cmallonee!

1 Like