# Close Vision Client Windows Using Shared Script

**URL:** <https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489>\
**Category:** Ignition\
**Tags:** vision, ignition81, scripting\
**Created:** [May 9, 2023, 5:33pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489 "2023-05-09T17:33:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![israel.jordan](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@israel.jordan](https://forum.inductiveautomation.com/u/israel.jordan)\
**Post date:** [May 9, 2023, 5:33pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/1 "2023-05-09T17:33:29Z")

</div>

Hi,  
I was doing some searching and couldn't find a topic on this. Is it possible to close a Vision Client window using a shared script from another project? It looks like I have access to the Client Id and the Address. I was thinking I might be able to use them to achieve my goals. If so, can someone point me to some documentation or the right direction to go about this?

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 9, 2023, 5:38pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/2 "2023-05-09T17:38:35Z")

</div>

It's a built in one-liner to exit a vision client `system.util.exit()` [system.util.exit - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.util.exit)

Don't know what your exact use case is. Are you trying to monitor live sessions and exit based on some criteria (like inactivity or something)?

---

<div class="post-metadata">

**Author:** ![israel.jordan](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@israel.jordan](https://forum.inductiveautomation.com/u/israel.jordan)\
**Post date:** [May 9, 2023, 5:40pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/3 "2023-05-09T17:40:31Z")

</div>

@bkarabinchak.psi Thank you for the reply. But I am not trying to close the client. I would like to close a certain window that the client has open.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 9, 2023, 5:42pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/4 "2023-05-09T17:42:11Z")

</div>

Ok, what is the criteria for closing that window?

That too is a built-in one liner `system.nav.closeWindow('myWindowPath')` [system.nav.closeWindow - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.nav.closeWindow)

---

<div class="post-metadata">

**Author:** ![israel.jordan](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@israel.jordan](https://forum.inductiveautomation.com/u/israel.jordan)\
**Post date:** [May 9, 2023, 5:45pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/5 "2023-05-09T17:45:02Z")

</div>

What if there is more than one client that has that window open? How will it choose the correct client?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 9, 2023, 5:46pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/6 "2023-05-09T17:46:36Z")

</div>

Well again what is the criteria to close this window? I'm wondering if you even need to use the gateway to manage this or if it can be done within a client timer script or similar. Then you would not need to worry about clientId's or sending messages between GW/client. But again, I don't know what your particulars are. What is the end goal? It's very possible this logic can be local to the window itself even.

---

<div class="post-metadata">

**Author:** ![israel.jordan](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@israel.jordan](https://forum.inductiveautomation.com/u/israel.jordan)\
**Post date:** [May 9, 2023, 5:49pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/7 "2023-05-09T17:49:06Z")

</div>

Well it is actually based on when some tcp data is received from a connected device. I have a tag change script on a tag that is configured to watch the device. The script calls the shared script and I would like to close the window using that script.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 9, 2023, 5:53pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/8 "2023-05-09T17:53:16Z")

</div>

Ok, I assume this device is connected to your gateway already, it has something a tag showing the data, and from the data you receive in this you are able to tell which client to close? Are these assumptions correct?

---

<div class="post-metadata">

**Author:** ![israel.jordan](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@israel.jordan](https://forum.inductiveautomation.com/u/israel.jordan)\
**Post date:** [May 9, 2023, 5:58pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/9 "2023-05-09T17:58:34Z")

</div>

Yes, the device is connected to the gateway already. I have access to the client id while in the shared script.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 9, 2023, 6:01pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/10 "2023-05-09T18:01:01Z")

</div>

You already have a shared script that is managing this data/knows about clients? In that case, operating from a gateway scope, do a `system.util.sendMessage()` [system.util.sendMessage - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.util.sendMessage) to the appropriate client with the `String clientSessionId - Limits the message delivery to a client with the specified session ID. [optional]` argument.

GW Side:

```auto
# Your logic to determine what client to close
clientToClose = 'someId'
system.util.sendMessage('someProject','closeSomeWindowMsg', scope='C', clientSessionId=clientToClose)

```

On the client side you will need to setup message handler, in this example called `closeSomeWindowMsg` to accept that message, and in that you should do something like

```auto
try:
    system.nav.closeWindow("someWindow")
except:
    # Window isn't open - except prevents an error popup
    pass

```

If it's not clear how to integrate with your existing script I think you will have to share your shared script.

---

<div class="post-metadata">

**Author:** ![israel.jordan](https://avatars.discourse-cdn.com/v4/letter/i/ce73a5/32.png) [@israel.jordan](https://forum.inductiveautomation.com/u/israel.jordan)\
**Post date:** [May 9, 2023, 6:06pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/11 "2023-05-09T18:06:30Z")

</div>

Thank you for the help. I think is the right direction!

---

<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:** [May 9, 2023, 6:11pm UTC](https://forum.inductiveautomation.com/t/close-vision-client-windows-using-shared-script/73489/12 "2023-05-09T18:11:25Z")

</div>

An important point of clarification I want to underscore:  
The 'project library' is just that - a _library_ of scripts. Scripts in the project library have no inherent scope. They're just "library" functions that can be called from anywhere - the **calling** scope is what determines your execution environment. You can (and often will) write scopes that are agnostic to being called from the gateway or a Vision client, with the prominence of both Perspective and Vision.
