Perspective :: How to init SESSION CUSTOM vars on startup session?


I am working in perspective.

I have several session custom that I want them to be initialized on the first run (session start).
ie: session.custom.pot_table_view.limit_param

However, If I set this session_custom variable within the onStartup(session) in the Session Events section, It seems not to be set.

There is a place to initialise custom session variable on session start (browser side)

I just tried to replicate this and it’s working for me. Just out of an abundance of caution, try this:

  1. Close all open sessions on your workspace.
  2. Wait until your Gateway shows no active Perspective Sessions on your workstation (Status > Perspective Sessions) (could be 120 seconds, depending on project settings).
  3. Open a new Session and see if your property is in place.
  4. If you now see the property, it’s probably because you had an open session already in place, and so the session wasn’t technically starting.

I am recommending this because I was able to replicate this only when I mistakenly left a Session running while I made changes to my onStartup script, and so didn’t see those changes reflected.

1 Like

I need to get userName from session.props.auth on startup to populate a custom session property, but it looks like it doesn’t exist whenever the session startup script is ran. I presume this is because, although our project requires authentication to view, the session startup script is fired prior to the user completing the log-in. Is this accurate?

If so, I am somewhat confused by the manual’s wording on session properties; shouldn’t auth be available, even if it’s null on startup?

Can you just add a change script to session.auth.user.userName?

1 Like

That’d work! Thanks!

I’m too optimistic. The property change script is only firing when I have a session open in the browser and I save the project in the designer (making sure to time out the session in between each try, just in case) – on 8.0.10 nightly.

I conclude that the auth session property is the property equivalent of Batman–dark and mysterious.

Yes. The onStartup is executed the moment the websocket connection is created - well before the user has actually logged in (if authentication is required).

The property change script should absolutely work. Bindings should also work.

8.0.10 nightly (b2020022002)

I created a new project, required authentication, and added property change scripts to all of the subproperties under auth, which are simply logging the name of the property as well as the new incoming value. I opened a new session and signed in. Again, it looks like property change scripts aren’t firing unless the session is open and I save the project.

For science, I also tried the same property change scripts on other session properties: id, host, device.identifier. The property change script on host fired upon opening a new session, but the others didn’t (sans designer saves).

Fortunately, bindings are working as expected, which make this easy to work around.