[FEATURE] Perspective - Add functions to read/write custom session props via script

Since custom session props now take the place of Vision Client tags, it would be useful to have script functions added to read and write to these as you would with tags (system.tag.read/write*)

For example:
system.perspective.sessionPropRead('custom.path.to.prop')
system.perspective.sessionPropWrite('custom.path.to.prop', 'newValue')

These would be useful and far more intuitive to newcomers.
For example, in Vision I might have a template with a string param where I could set it to the path of a Vision client tag, then inside the template I could read and write to the tag via script with the system.tag.read/write* functions, all searchable within the “intellisense” or the user manual if you weren’t aware these existed.

In Perspective, this is still possible, you can pass the View template a path to the custom session prop and then read/write it from script, however you must use the standard Python functions setattr and getattr which aren’t inherently obvious, especially not for newcomers!
E.g.

# read session.custom prop value
getattr(self.session.custom, self.view.params.sessionCustomPropPath)`

# set session.custom prop value
setattr(self.session.custom, self.view.params.sessionCustomPropPath, 'newValue')
3 Likes

Yes please, setattr is a bit too clunky for my use case (using a template repeater that looks at session custom properties). As an addition to this, maybe an indirect property binding could be added as well?

This was exactly my use-case (well, a flex repeater which I assume you meant).
I didn't find it all that clunky, as I would have to do the same thing if we had these functions as well, it just would have been far more obvious that that's what I had to use. Even having used get/setattr before in Vision, it took me a while and a forum search for it to click.

Are you talking similar to the indirect tag binding where, importantly, you can set it to be bidirectional? This would certainly be useful as well! (The expression language already has the property() function which is specifically for indirectly reading properties, however it doesn't support bidirection (and obviously doesn't support writing - no expression function does))

Yes flex repeater, I also ran into the same issue of forgetting it existed, and searching the forums to find a post from myself a few months ago.

And yes, bidirectional most importantly

Has anything like this been released, or a workaround found?
I’m struggling to get my navigation scheme to work. I’d like to have session custom properties that define some pieces of information that will be used for navigating per session.
I want a central place / function to write to these parameters.

I tried using a message handler on the Project/Perspective/Session Events, but i’ve found that that is running on a different session thread to my actual browser sessions, and for some reason when i use the following code in the handler, it sets the session property across ALL sessions, which is undesirable.

def handleMessage(session, payload):
	session.custom.headerTitle = payload["value"]