# Perspective - How to run script upon login

**URL:** <https://forum.inductiveautomation.com/t/perspective-how-to-run-script-upon-login/96611>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [September 30, 2024, 2:32pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-run-script-upon-login/96611 "2024-09-30T14:32:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isabela\_Babcock](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@Isabela\_Babcock](https://forum.inductiveautomation.com/u/Isabela_Babcock)\
**Post date:** [September 30, 2024, 2:32pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-run-script-upon-login/96611/1 "2024-09-30T14:32:59Z")

</div>

Hello,

**What I want**  
I have a custom script I want to run that will call a named query to retrieve user information and save it to a _Session custom property_, taking _session.props.auth.user.userName_ as the parameter. In other words, I want to call this custom script as soon as the userName session property is populated when the user logs in. This script only needs to run after the user has been authenticated.

**What I tried**

- Session Events: Startup, Page Startup, Authentication Challenge, and Message.
- Change script on session.props.auth.user.userName

Any recommendations on how I could accomplish this? In none of my attempts was I able to access the username property dynamically.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Noah\_Casey](https://avatars.discourse-cdn.com/v4/letter/n/e480ec/32.png) [@Noah\_Casey](https://forum.inductiveautomation.com/u/Noah_Casey)\
**Post date:** [September 30, 2024, 2:47pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-run-script-upon-login/96611/2 "2024-09-30T14:47:00Z")

</div>

There are a few ways to do this:

**1:** You can create a custom session property set a binding to the property for:

```python
this.props.auth.user.userName

```

Then you can add a transform as either the script or a trigger to run the existing script.

**2:** You could do the same using the expression language and [runscript](https://www.docs.inductiveautomation.com/docs/8.1/appendix/expression-functions/advanced/runScript)

**3:** If it's just a named query you want to run create a session property with a query binding and have the _this.props.auth.user.userName_ as the parameter.

---

<div class="post-metadata">

**Author:** ![Isabela\_Babcock](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@Isabela\_Babcock](https://forum.inductiveautomation.com/u/Isabela_Babcock)\
**Post date:** [September 30, 2024, 3:09pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-run-script-upon-login/96611/3 "2024-09-30T15:09:43Z")

</div>

Thank you @Noah_Casey  
If I go with option 3, do you know how often the script would run? I wanted to run only once for the entirety of the session.

---

<div class="post-metadata">

**Author:** ![jonathan.taylor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jonathan.taylor/32/4048_2.png) [@jonathan.taylor](https://forum.inductiveautomation.com/u/jonathan.taylor)\
**Post date:** [September 30, 2024, 3:10pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-run-script-upon-login/96611/4 "2024-09-30T15:10:14Z")

</div>

You can set the polling to be off, so would only update once

---

<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 30, 2024, 3:10pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-run-script-upon-login/96611/5 "2024-09-30T15:10:38Z")

</div>

It will run once each time the property changes (with polling off).

---

<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:** [September 30, 2024, 3:11pm UTC](https://forum.inductiveautomation.com/t/perspective-how-to-run-script-upon-login/96611/6 "2024-09-30T15:11:23Z")

</div>

Whatever path you take, you will have to allow for the empty user name when logged out. The bindings will still run for that.
