# Open pop up with tag event script ( Valued change)

**URL:** <https://forum.inductiveautomation.com/t/open-pop-up-with-tag-event-script-valued-change/56537>\
**Category:** Ignition\
**Tags:** scripting, ignition81\
**Created:** [February 24, 2022, 10:03pm UTC](https://forum.inductiveautomation.com/t/open-pop-up-with-tag-event-script-valued-change/56537 "2022-02-24T22:03:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![uy\_huynh](https://avatars.discourse-cdn.com/v4/letter/u/54ee81/32.png) [@uy\_huynh](https://forum.inductiveautomation.com/u/uy_huynh)\
**Post date:** [February 24, 2022, 10:03pm UTC](https://forum.inductiveautomation.com/t/open-pop-up-with-tag-event-script-valued-change/56537/1 "2022-02-24T22:03:31Z")

</div>

Based on this link [Open popup from session event - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/open-popup-from-session-event/53148/5), 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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 24, 2022, 10:13pm UTC](https://forum.inductiveautomation.com/t/open-pop-up-with-tag-event-script-valued-change/56537/2 "2022-02-24T22:13:04Z")

</div>

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()`.

---

<div class="post-metadata">

**Author:** ![uy\_huynh](https://avatars.discourse-cdn.com/v4/letter/u/54ee81/32.png) [@uy\_huynh](https://forum.inductiveautomation.com/u/uy_huynh)\
**Post date:** [February 24, 2022, 11:17pm UTC](https://forum.inductiveautomation.com/t/open-pop-up-with-tag-event-script-valued-change/56537/3 "2022-02-24T23:17:14Z")

</div>

so this is my value changed:

```auto
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**

`

```auto
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**  
`

```auto
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!

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 24, 2022, 11:28pm UTC](https://forum.inductiveautomation.com/t/open-pop-up-with-tag-event-script-valued-change/56537/4 "2022-02-24T23:28:02Z")

</div>

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

```auto
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).

---

<div class="post-metadata">

**Author:** ![uy\_huynh](https://avatars.discourse-cdn.com/v4/letter/u/54ee81/32.png) [@uy\_huynh](https://forum.inductiveautomation.com/u/uy_huynh)\
**Post date:** [February 24, 2022, 11:37pm UTC](https://forum.inductiveautomation.com/t/open-pop-up-with-tag-event-script-valued-change/56537/5 "2022-02-24T23:37:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chandrasekar\_s](https://avatars.discourse-cdn.com/v4/letter/c/8baadc/32.png) [@chandrasekar\_s](https://forum.inductiveautomation.com/u/chandrasekar_s)\
**Post date:** [March 27, 2024, 6:31am UTC](https://forum.inductiveautomation.com/t/open-pop-up-with-tag-event-script-valued-change/56537/6 "2024-03-27T06:31:13Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/f/afdb179355715d8c7448c1ed32412537475a93b5.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/d/3d46693b3e5147c570771943a091417ad4f8df76.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [March 27, 2024, 8:48am UTC](https://forum.inductiveautomation.com/t/open-pop-up-with-tag-event-script-valued-change/56537/7 "2024-03-27T08:48:51Z")

</div>

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

> **[Component Message Handlers | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/ignition-modules/perspective/scripting-in-perspective/component-message-handlers#message-handler-scope)**
>
> In Perspective, Component Message Handlers are the preferred way to pass parameters between components or Views. Doing this involves the system.perspective.sendMessage function. There are typically two steps involved:

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [March 27, 2024, 3:01pm UTC](https://forum.inductiveautomation.com/t/open-pop-up-with-tag-event-script-valued-change/56537/8 "2024-03-27T15:01:35Z")

</div>

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.
