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

Hi Cmallonee,

In the same way, I'm trying to send a message to my message once the tag value changes but in the label, I can't get the text value from my label.

so could please help me with this

Please find the Images below attached


And in the same way as shown in post #4, you have to provide the scope for the message.

Tags do not live in a Perspective Session, so they may not invoke (most) Perspective package functions. If you look in your logs, you will see failed usages for each time that script executes.

Why are you sending this as a message instead of just binding some property within the session against the Tag Value? Configure a custom session property, then bind that prop against your Tag. Place a change script on the property. Be aware though that session property change scripts may not directly open Popups - Session property change scripts which attempt to do this MUST specify a pageId kwarg to the openPopup function.

1 Like