# Closing a Window from Client Tag Event Script

**URL:** <https://forum.inductiveautomation.com/t/closing-a-window-from-client-tag-event-script/52575>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [November 1, 2021, 4:40pm UTC](https://forum.inductiveautomation.com/t/closing-a-window-from-client-tag-event-script/52575 "2021-11-01T16:40:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrebro](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rrebro](https://forum.inductiveautomation.com/u/rrebro)\
**Post date:** [November 1, 2021, 4:40pm UTC](https://forum.inductiveautomation.com/t/closing-a-window-from-client-tag-event-script/52575/1 "2021-11-01T16:40:34Z")

</div>

I am trying to setup a popup to open when a tag is 1 and close when a value is 0. Here is the code I am using. Right now I am just closing all windows to see if I can get anything to close. I am unable to close windows, this is in a client tag change script. Why can I not close the window but I can open it.

I ran the same code on a button script and everything closed, so I expect this to be an issue with it being in a client tag change script.

```auto
if(event.getCurrentValue().getValue() == 1):
	window = system.nav.openWindow('Popup Window')
	system.nav.centerWindow(window)
else:
	windows = system.gui.getOpenWindows()
	for window in windows:
		system.nav.closeWindow(window.getPath())

```

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [November 3, 2021, 2:20pm UTC](https://forum.inductiveautomation.com/t/closing-a-window-from-client-tag-event-script/52575/2 "2021-11-03T14:20:40Z")

</div>

Hi, maybe you’ve solved this by now since you seem to get what’s wrong with it.  
This is what worked for me:

1. Create a Tag Change Script under Vision-Client Events.

2. The script’s “Change Triggers” should be Value only to make sure it only executes when you want to.

3. Under “Tag Path(s)”, choose the tag you want to monitor

4. On the Script tab, your script should look something like this:

```auto
#Check if your tag value is correct
if newValue.getValue() == 1:
	window = system.nav.openWindow('Popup Window')
	system.nav.centerWindow(window)
else:
	windows = system.gui.getOpenWindows()
	for window in windows:
		system.nav.closeWindow(window.getPath())

```

Some considerations:  
If your tag value can change while you don’t have a client running, you might encounter a situation where the your popup won’t open because the client wasn’t there to check the initial change.  
If you want more information about scripting scope, you can check out this page where it mentions scripting scope:  
[https://docs.inductiveautomation.com/display/DOC81/Scripting+in+Ignition](https://docs.inductiveautomation.com/display/DOC81/Scripting+in+Ignition)  
If you’re in doubt where your script function falls under the scripting scope, you can check out the function’s page where you can see it under Syntax:  
[https://docs.inductiveautomation.com/display/DOC81/system.nav.openWindow](https://docs.inductiveautomation.com/display/DOC81/system.nav.openWindow)

---

<div class="post-metadata">

**Author:** ![rrebro](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rrebro](https://forum.inductiveautomation.com/u/rrebro)\
**Post date:** [November 3, 2021, 2:38pm UTC](https://forum.inductiveautomation.com/t/closing-a-window-from-client-tag-event-script/52575/3 "2021-11-03T14:38:41Z")

</div>

Right, I got all this. I am using the same code as you in a Vision Client Tag Change Script and I have a Client Open, But when the tag changes to 0, the windows do not close. That’s my problem

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [November 3, 2021, 3:06pm UTC](https://forum.inductiveautomation.com/t/closing-a-window-from-client-tag-event-script/52575/4 "2021-11-03T15:06:22Z")

</div>

Oh ok, can you try using this script instead?

```auto
window = ''Popup Window''
tagValue = newValue.getValue()
if tagValue == True:
	system.nav.openWindow(window)
elif tagValue == False:
	system.nav.closeWindow(window)

```

---

<div class="post-metadata">

**Author:** ![rrebro](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rrebro](https://forum.inductiveautomation.com/u/rrebro)\
**Post date:** [November 3, 2021, 3:23pm UTC](https://forum.inductiveautomation.com/t/closing-a-window-from-client-tag-event-script/52575/5 "2021-11-03T15:23:06Z")

</div>

Yes, that worked. Any thoughts on why the other code did not ?

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [November 3, 2021, 4:58pm UTC](https://forum.inductiveautomation.com/t/closing-a-window-from-client-tag-event-script/52575/6 "2021-11-03T16:58:11Z")

</div>

I did some tests and discovered that the code works if you change the function name from “system.gui.getOpenWindows” to “system.gui.getOpenedWindows”. Also discovered that the elif that i’ve used is unecessary since there’s no problem with the evaluation.  
You can also change the .getOpenedWindows to .getOpenedWindowNames and you won’t have to use window.getPath() later.

---

<div class="post-metadata">

**Author:** ![rrebro](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@rrebro](https://forum.inductiveautomation.com/u/rrebro)\
**Post date:** [November 3, 2021, 4:59pm UTC](https://forum.inductiveautomation.com/t/closing-a-window-from-client-tag-event-script/52575/7 "2021-11-03T16:59:42Z")

</div>

You got it. Thanks for catching that for me 😁

---

<div class="post-metadata">

**Author:** ![leonardo.godoi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/leonardo.godoi/32/27178_2.png) [@leonardo.godoi](https://forum.inductiveautomation.com/u/leonardo.godoi)\
**Post date:** [November 3, 2021, 5:06pm UTC](https://forum.inductiveautomation.com/t/closing-a-window-from-client-tag-event-script/52575/8 "2021-11-03T17:06:19Z")

</div>

You’re welcome, i’m glad i was able to help. I should’ve picked up on that earlier, if only i had read carefully what you wrote initially…
