# Client Event Script For Switching User

**URL:** <https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [January 12, 2023, 10:49pm UTC](https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558 "2023-01-12T22:49:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Gonsior](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@David\_Gonsior](https://forum.inductiveautomation.com/u/David_Gonsior)\
**Post date:** [January 12, 2023, 10:49pm UTC](https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558/1 "2023-01-12T22:49:33Z")

</div>

So I created a timer-based script for switching users after a preset time. I used the following structure: system.security.switchUser(username, password, event, hideError ). What would go into the event parameter?  
All I'm trying to accomplish is logging out of any other user that maybe logged in, and re-logging back in to a lower-level user.

if system.util.getInactivitySeconds () \>15:  
system.security.switchUser(Default,Default,WHATGOESHERE??,0)

---

<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:** [January 12, 2023, 10:55pm UTC](https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558/2 "2023-01-12T22:55:12Z")

</div>

You don't have to pass anything for the event parameter. It's optional.

---

<div class="post-metadata">

**Author:** ![David\_Gonsior](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@David\_Gonsior](https://forum.inductiveautomation.com/u/David_Gonsior)\
**Post date:** [January 13, 2023, 3:36pm UTC](https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558/3 "2023-01-13T15:36:29Z")

</div>

Okay. Any other things I should be looking at?...the script doesn't seem to be executing.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 13, 2023, 3:44pm UTC](https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558/4 "2023-01-13T15:44:41Z")

</div>

Post your actual, complete code. Not a screenshot. Paste it into a comment. Select all of the code and then click the "Preformatted Text" button to make a code block.

---

<div class="post-metadata">

**Author:** ![David\_Gonsior](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@David\_Gonsior](https://forum.inductiveautomation.com/u/David_Gonsior)\
**Post date:** [January 13, 2023, 3:49pm UTC](https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558/5 "2023-01-13T15:49:38Z")

</div>

```auto
if system.util.getInactivitySeconds () >15:
	system.security.switchUser(Default,Default,(),0)

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [January 13, 2023, 3:56pm UTC](https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558/6 "2023-01-13T15:56:26Z")

</div>

I see a space between the `()` and `getInactivitySeconds`, but that may be a typo. You will also want to check the current user before you `switchUser` otherwise you will switch user every 15 seconds no matter who is logged in. I've made that mistake myself. Is `Default` the string name, or a variable?

```python
if system.util.getInactivitySeconds() > 15 and system.security.getUsername() != "Default":
    system.security.switchUser("Default","Default")

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [January 13, 2023, 3:58pm UTC](https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558/7 "2023-01-13T15:58:56Z")

</div>

The manual doesn't list the `event` parameter as optional.  
[system.security.switchUser - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)](https://docs.inductiveautomation.com/display/DOC81/system.security.switchUser)

Edit:  
Well, it does say `if specified, ...` but I think the optional tag would be helpful.

---

<div class="post-metadata">

**Author:** ![David\_Gonsior](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@David\_Gonsior](https://forum.inductiveautomation.com/u/David_Gonsior)\
**Post date:** [January 13, 2023, 4:15pm UTC](https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558/8 "2023-01-13T16:15:38Z")

</div>

Worked like a charm. Thanks so much!!

---

<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:** [January 13, 2023, 4:36pm UTC](https://forum.inductiveautomation.com/t/client-event-script-for-switching-user/68558/9 "2023-01-13T16:36:51Z")

</div>

> [@David\_Gonsior](#):
>
> `system.security.switchUser(Default,Default,(),0)`

I'm not sure what language you might be coming from, but it's worth pointing out:  
Python optional parameters are _truly optional_. You don't have to specify a default or empty value; you just don't specify one at all.

What you're doing here is passing an empty tuple for the event parameter. It's up to the function you're calling if passing the "wrong" type throws an error, is ignored, or does something different from your expectation.
