I would like to access custom session property names and their corresponding values in a script so that I can save them to a database table. Is there a function in Ignition that will return an object/dataset containing the custom session properties and the corresponding values? If not, how can I access custom session property names and values in a script?
I’d like to access an object or something similar that looks like this:
{Custom Session Property 1: Value of Custom Session Property 1, … Custom Session Property n: Value of Custom Session Property n}
You've mentioned 'session' so I'm assuming Perspective. (There are optional tags below your title. I'll add it in.)
Any view or component on the view can access the session props. To get the object it would just be something like, myProps = self.session.custom.myCustomProps
and you can find this using the Browse Properties button on the script editor.
To save to a database you'll need to decide the column format. For a string column, for example, you'd need to convert the JSON to a string.
Let us know which flavour of database you're using.
Got it, thank you for the information. Is it also possible to do something like myProps = self.session.custom.myCustomProps in a project or gateway script? Can I get custom session properties outside of views and view components.
You have to access the session properties from a session scope. That is not to say that you can't have project library scripts which are intended to work with session properties, but you have to send the 'self' object to the function.
Note: Project library scripts run in the scope that they are called from, they do not have any defined scope.
If by gateway scripts, you mean Gateway Event Scripts, then other than message handlers, there isn't really a way to send the session object to them. You'll need to be more specific with what you're trying to accomplish to get a better answer.