# Run a Script when a vision client loses connection to the gateway

**URL:** <https://forum.inductiveautomation.com/t/run-a-script-when-a-vision-client-loses-connection-to-the-gateway/44266>\
**Category:** Ignition\
**Tags:** vision, scripting, ignition80\
**Created:** [March 9, 2021, 3:58pm UTC](https://forum.inductiveautomation.com/t/run-a-script-when-a-vision-client-loses-connection-to-the-gateway/44266 "2021-03-09T15:58:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgonya](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgonya/32/9304_2.png) [@jgonya](https://forum.inductiveautomation.com/u/jgonya)\
**Post date:** [March 9, 2021, 3:58pm UTC](https://forum.inductiveautomation.com/t/run-a-script-when-a-vision-client-loses-connection-to-the-gateway/44266/1 "2021-03-09T15:58:23Z")

</div>

I have a client event script on shutdown and it runs when the app is closed or when the user logs out. The script runs a names query and update a database to track how long a user is using the app. However sometimes the PC that the client is running on loses connection to the gateway. So the script on shutdown doesn’t run. Is there away to run a script when the connection is lost? I was thinking about a Gateway Event Scripts on tag change maybe. Any help would be greatly appreciated, Thank you.

---

<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:** [March 9, 2021, 5:55pm UTC](https://forum.inductiveautomation.com/t/run-a-script-when-a-vision-client-loses-connection-to-the-gateway/44266/2 "2021-03-09T17:55:28Z")

</div>

Do your telemetry the other way around. Run a periodic task on the _gateway_, that collects all clients it ‘knows’ about (via [`system.util.getSessionInfo`](https://docs.inductiveautomation.com/display/DOC81/system.util.getSessionInfo)) - and then check for ‘missing’ sessions compared to the last run to know when to ‘close’ a session in your monitoring.
