How to Read Session Custom Variables in a Tag Value Change Script?

Hi everyone,

I need to access session custom variable values within a Tag Value Changed script. Is there a way to retrieve all the session custom variables from this script context?

Any suggestions or best practices would be greatly appreciated!

Thanks in advance.

This is not really ever going to work, tag change scripts run on the gateway, session variables are unique to every session on the gateway.

Explain what you are trying to achieve, and we will likely have a way to achieve it.

irst, thanks for your reply.

At the start of the session, we create several custom variables with predefined values. Later, we use these variables to update different tag values as needed.

For example, if the value of Tag A changes from 10 to 5, we want to update Tag B using the value of a session custom variable (e.g., V1).

I hope this clarifies why we need to access session variables in this context.

Why do you create them as session variables? Do they change based on each user logged on?
Are they the same values for every user logged on?

Yes, these values are the same for all users.

We have created them as global variables, but as you know, in Perspective we cannot directly create true global variables.

Is there any way to read these variables within a Tag Value Change script?

A global variable in Ignition is a Memory Tag, don’t use these as session variables.
Make a memory tag and set your tag change script to change the value using writeBlocking().

2 Likes

This is possible, but a bit dangerous as users are not guaranteed to have the same session parameter value. If you never change these and its the same for every user its probably. safe enough, but there is almost certainly a better way to go about it.

Writting to a memory tag like @David_Stone stated, should work.

No. That's is why you are being directed to use other techniques.

In Ignition, the type of variable that is persistent and is common to all users is the memory tag.

If you needed something that was per-user, and also needed to react to tag changes, you would bind the tag into a session custom property, and write a property change script there (not on the tag).

Thanks alot David and Pturmel.