Perspective - How to run script upon login

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!

There are a few ways to do this:

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

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

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.

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.

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

1 Like

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

4 Likes

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

1 Like