# \[SOLVED\] Open window in script tag changed

**URL:** <https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653>\
**Category:** Ignition\
**Tags:** vision, ignition81\
**Created:** [August 31, 2022, 8:30pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653 "2022-08-31T20:30:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [August 31, 2022, 8:30pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/1 "2022-08-31T20:30:11Z")

</div>

Hello everyone, I want to open a window after a tag value change inside the script tag but did not work and I tried changing manually the tag while running the project, can anyone help me please?

```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 != currentValue.value:
		system.nav.openWindowInstance("User Management/mensajeAlarma")

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 31, 2022, 8:42pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/2 "2022-08-31T20:42:51Z")

</div>

~~Is this a custom method on a component that is bound in some way to the tag?~~

Edit: Disregard; I see now what you are saying

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 31, 2022, 8:44pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/3 "2022-08-31T20:44:18Z")

</div>

Unless this is a [client-scoped tag change script](https://docs.inductiveautomation.com/display/DOC81/Client+Event+Scripts#ClientEventScripts-TagChangeScripts), your execution context is wrong and this will never work.  
A tag running on the gateway does not ‘know’ _which_ client you are attempting to open a window instance on.

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [August 31, 2022, 9:01pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/4 "2022-08-31T21:01:14Z")

</div>

So , when the tag change, needs to open the window

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [August 31, 2022, 9:42pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/5 "2022-08-31T21:42:20Z")

</div>

And am I have to run the project in the client or can I with the gateway only?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 31, 2022, 10:32pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/6 "2022-08-31T22:32:12Z")

</div>

_You_ need to decide what happens and where.  
Does _every single open client_ need to react to this tag changing, or a particular one? Or only one opened by an administrator, or some other requirement?

If every client needs to react to some tag changing, then you need a client-scoped tag change event. See the manual page I linked earlier. That will make every open client automatically “watch” the tag you supply, and as soon as it changes, run your script.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [August 31, 2022, 10:37pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/7 "2022-08-31T22:37:33Z")

</div>

**If you want every client to see the pop-up on a tag change, then, I believe this is what you are wanting to do:**  
 ![Example Part 1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/7/37e95fb076930f9566cd9ddc2604d14927ea9045.png)

 ![Example Part 2](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/b/3b1ad9c3e0f33574cb064c95281c7106ba233019.png)  
 ![Example Part 3](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/f/3fc2a35a4c3eaba87c10a31045cd4b96c4418d72.png)

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [August 31, 2022, 10:38pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/8 "2022-08-31T22:38:23Z")

</div>

Thank you so much

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [August 31, 2022, 10:39pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/9 "2022-08-31T22:39:05Z")

</div>

Thank you so much for the help, it worked

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [September 26, 2022, 8:49pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/10 "2022-09-26T20:49:23Z")

</div>

Hello, It worked, when the tag change the window instance is open but if there is more than one window open, if I apply a clic inside my principal window, the instance disappear → For example:  
The number 1 is my instance and the number 2 is the principal window, so when I do a clic in the principal window, the number 1 disappear

 ![gain-administartor-access-uninstall-programs-server](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/9/79093d7c1fc0bc1806f51bfc5cdedf79065f21df.png)

and I want it fixed as stay there until I close the window, because has a button that close the window.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 26, 2022, 11:00pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/11 "2022-09-26T23:00:51Z")

</div>

@Esmeralda_Lopez

In my attempt to recreate the problem, I’ve taken the following steps:

- I created a Boolean tag called Test Tag, and popup window called Popup.
- Then, I set up a tag change client event script to open the popup if the tag changes state.

When I launch the project and subsequently change the Boolean value, the popup opens as expected, but when I click on the main window, causing the popup to loose focus, the popup doesn’t close as you are describing.

Is it possible that you have a script on the main window or the popup itself that is automatically closing the popup when it looses focus?

Look at your project browser, and check to see if there is any scripting:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/4/848f66d1469ce0f83aa778cc7fd77f9bb34b790b.png)

Look for something like this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/c/ec85da275d9cffe890edd3cff3980e6a87a8c1dd.png)

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [September 26, 2022, 11:33pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/12 "2022-09-26T23:33:45Z")

</div>

I found that I was using a Main window and I changed to a pop up as should be, that is why, and not , I don’t have any script that is closing automatically the window.

But now are happening two things:

1. If I have 3 instances of pop up window open, so I am located at the third pop up that opened and if I clic on other pop up, both windows will have the same values in the labels and I don’t want that because I need to stay the different values in each pop up.

2. When I try to close the third pop up (as in this example), only close the first one , then the second and at the final the third pop up. → 

So I have this order where the first one is the last pop up that opened:

3 (third) window-pop up - last to open  
2 (second) window-pop up  
1 (first) window-pop up - first to open

I choose close the third and is closing the windows in the next order.  
1,2,3 when I need to close the pop up that I choose .

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [September 28, 2022, 3:40pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/13 "2022-09-28T15:40:44Z")

</div>

I have a question, because followind my code:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/c/dcf5ba88f3df84b9906d9ab5667cb2b6c42e26e1.png)

```auto
if event.getCurrentValue().getValue()!=event.getPreviousValue().getValue():
	if event.getCurrentValue().getValue():
		system.nav.openWindowInstance("User Management/mensajeAlarma")

```

I got this error :  
at org.python.core.PyTableCode.call(PyTableCode.java:173)  
at org.python.core.PyCode.call(PyCode.java:18)  
at org.python.core.Py.runCode(Py.java:1687)  
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:806)  
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:752)  
at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:241)  
at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:193)  
at com.inductiveautomation.ignition.common.util.SerialExecutionQueue$PollAndExecute.run(SerialExecutionQueue.java:102)  
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)  
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)  
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)  
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)  
at java.base/java.lang.Thread.run(Unknown Source)  
Caused by: org.python.core.PyException: AttributeError: ‘NoneType’ object has no attribute ‘getValue’

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 28, 2022, 3:48pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/14 "2022-09-28T15:48:27Z")

</div>

`getPreviousValue` can return `null` if the `initialChange` flag is set:

> [@Gateway scripting - previous value](https://forum.inductiveautomation.com/t/gateway-scripting-previous-value/64568/2):
>
> What doesn’t work about it? Keep in mind the first time the script executes there is no previous value, so it will be null / Python None, which you need to check for before you try to access its value component.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 28, 2022, 4:07pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/15 "2022-09-28T16:07:05Z")

</div>

@Esmeralda_Lopez  
If your tag is Boolean [True, False], then you can simplify your code to this:

```auto
if event.getCurrentValue().value:
	system.nav.openWindowInstance("User Management/mensajeAlarma")

```

That will eliminate the problem.

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [September 28, 2022, 5:04pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/16 "2022-09-28T17:04:53Z")

</div>

The tag is String because is a Tag memory and in some part of the project something write to the memory tag.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 29, 2022, 12:33am UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/18 "2022-09-29T00:33:38Z")

</div>

To complete this thread, there were three additional problems listed that either have been solved, or are close to being solved:

**Problem 1:**

> [@Esmeralda\_Lopez](#):
>
> I click on other pop up, both windows will have the same values in the labels

This was being caused by the population script being fired from the internalFrameActivated event handler which is triggered anytime a window gains focused. It was fixed by moving the script to the internalFrameOpened event handler which only gets launched when the window is initially opened, and is subsequenly never triggered again.

**Problem 2:**

> [@Esmeralda\_Lopez](#):
>
> I choose close the third and is closing the windows in the next order.  
> 1,2,3 when I need to close the pop up that I choose .

The cause of this was that the script for closing the window was using the ambiguous path/window name for the close command. `system.nav.closeWindow("Path/windowName")` Since each window instance had the same path and name, there was no guarantee that the intended window would close. This was fixed by using the following script instead:

```auto
window = system.gui.getParentWindow(event)
system.nav.closeWindow(window)

```

This script identifies which window that the event originated from, and then closes that specific window.

**Problem 3:**  
The client tag change event script was producing the following error:

> [@Esmeralda\_Lopez](#):
>
> NoneType’ object has no attribute ‘getValue’

I'm not sure if this is solved yet or not, but the way the code was written, the popup would have launched at start up whether or not the string had changed. Furthermore, the tag in question was a string datatype, and in the second if statement, the string was being treated like a bool, so I imagine that this would probably not work as intended. As @paul-griffith suggested, the code should probably be written like this:

```auto
if event.getPreviousValue() is not None and event.getCurrentValue()!=event.getPreviousValue():
	system.nav.openWindowInstance("User Management/mensajeAlarma")

```

In this way, the popup will not be triggered during the startup event, but will be triggered during any subsequent tag change.

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [September 29, 2022, 6:28pm UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/19 "2022-09-29T18:28:38Z")

</div>

Problem 1: Solved  
Problem 2: Solved, I was just closing the window  
Problem 3: It worked, but if the tag at the first when the last value went :  
Label1 | Label 2  
02 | 07

Then the tag change to for the first time to-\>  
Label1 | Label 2  
09 | 07

The pop up appears with :  
Label1 | Label 2  
02 | 07

So the value of the label 1 is the previous value and is not changing to the current value at the first time, then later is changing correctly after the first time but just after that.  
The code is :

```auto
tagPaths = ['[default]app_tags/Componentes/ArranquePedidos/Alarma_Canal_Vacio','[default]app_tags/Componentes/ArranquePedidos/Alarma_Sector_Vacio']
tgCanal, tgSector = [qval.value for qval in system.tag.readBlocking(tagPaths)]

if tgCanal:
    #system.nav.centerWindow('User Management/mesajeAlarma')
	
    system.gui.getParentWindow(event).getComponentForPath('Root Container.lblCanalTag').text = tgCanal
    system.gui.getParentWindow(event).getComponentForPath('Root Container.lbSectorTag').text = tgSector

```

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

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 30, 2022, 12:54am UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/20 "2022-09-30T00:54:57Z")

</div>

> [@Esmeralda\_Lopez](#):
>
> the value of the label 1 is the previous value and is not changing to the current value at the first time

I was unable to replicate the behavior testing in a live session using this code for my internalFrameOpened event handler:

```auto
tagPaths = ['[default]app_tags/Componentes/ArranquePedidos/Alarma_Canal_Vacio','[default]app_tags/Componentes/ArranquePedidos/Alarma_Sector_Vacio']
tgCanal, tgSector = [qval.value for qval in system.tag.readBlocking(tagPaths)]
system.gui.getParentWindow(event).getComponentForPath('Root Container.lblCanalTag').text = tgCanal
system.gui.getParentWindow(event).getComponentForPath('Root Container.lbSectorTag').text = tgSector

```

In my test, I used the Alarma\_Canal\_Vacio tag to trigger the tag change event script. Both tags are string datatype. I did remove the `if tgCanal:` statement from the code because that doesn't seem to be needed, but when I went back and tried the script with the if statement, I still got the expected result. Do you see anything in my experiment that differs from your approach?

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [September 30, 2022, 1:11am UTC](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653/21 "2022-09-30T01:11:32Z")

</div>

So, it worked for you ?

[Next page](https://forum.inductiveautomation.com/t/solved-open-window-in-script-tag-changed/63653.md?page=2)
