# Way to write to perspective sesson properties from wherever?

**URL:** <https://forum.inductiveautomation.com/t/way-to-write-to-perspective-sesson-properties-from-wherever/35053>\
**Category:** Ignition\
**Tags:** ignition80, scripting\
**Created:** [May 26, 2020, 6:23pm UTC](https://forum.inductiveautomation.com/t/way-to-write-to-perspective-sesson-properties-from-wherever/35053 "2020-05-26T18:23:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 26, 2020, 6:23pm UTC](https://forum.inductiveautomation.com/t/way-to-write-to-perspective-sesson-properties-from-wherever/35053/1 "2020-05-26T18:23:49Z")

</div>

I have a function that handles a banner messaging system that exists in both the Vision and Perspective version of our application. I am trying to merge their shared set of scripts into one script module.

Then function writes the banner message to the database, and then 1) toggles a client tag to refresh the query or 2) toggled a session custom property that’s used in the named query to do the same in perspective. But now I am trying to merge these together into one function that is called after the database write completes.

I have this working for vision but don’t know what I can put in perspective to make it work

```auto
def refreshMessages():
    from env import isPerspective, isVision
    if isPerspective():
        #????
    elif isVision(): # This tells the table to refresh(vision)
        import system.tag
	    if system.tag.read('[client]refreshMessages'):
	    	system.tag.write('[client]refreshMessages', 0)
	    else:
	    	system.tag.write('[client]refreshMessages', 1)

```

Is there a way to read/write directly to a session property analogous to system.tag?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 26, 2020, 6:30pm UTC](https://forum.inductiveautomation.com/t/way-to-write-to-perspective-sesson-properties-from-wherever/35053/2 "2020-05-26T18:30:11Z")

</div>

Python’s builtin functions `getattr` and `setattr` - although you’ll need to get a generic reference to the session object inside your `refreshMessages` function. I think I posted a possible way to do that here on the forums a while back…there’s a relevant caution right below it from @pturmel 🙂

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 26, 2020, 6:34pm UTC](https://forum.inductiveautomation.com/t/way-to-write-to-perspective-sesson-properties-from-wherever/35053/3 "2020-05-26T18:34:02Z")

</div>

Ok, looking through your posts, any tips to find it?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 26, 2020, 6:36pm UTC](https://forum.inductiveautomation.com/t/way-to-write-to-perspective-sesson-properties-from-wherever/35053/4 "2020-05-26T18:36:49Z")

</div>

> [@Referencing a session prop from a script library?](http://forum.inductiveautomation.com/t/referencing-a-session-prop-from-a-script-library/33314/4):
>
> So there is nothing to replace Client tags in 8.0? I have almost 100 functions defined in a script library and want to change the database they point to based on the plant selected. I have a session property that does this for everything else but I can’t use it at the beginning of the script library? I would have to pass it into each function separately.

From a post from me. I thought I had made a post on this. Boy do I have egg on my face.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [May 26, 2020, 6:56pm UTC](https://forum.inductiveautomation.com/t/way-to-write-to-perspective-sesson-properties-from-wherever/35053/5 "2020-05-26T18:56:33Z")

</div>

I tried doing this

```auto
def refreshMessages():
    from test import universalPrint as uPrint
	if isPerspective():
		uPrint('Env is Perspective')
		uPrint('here 1')
		from com.inductiveautomation.perspective.gateway.session import InternalSession
		uPrint('here 2')
		session = InternalSession.SESSION.get()
		uPrint('here 3')
		uPrint("session: " + str(session))
		value = getattr(session.custom, "refreshMessages")
		if value == 0:
			setattr(session.custom, "refreshMessages",1)
		else:
			setattr(session.custom, "refreshMessages",0)
	else: # This tells the table to refresh(vision)
		uPrint('Env is Vision')
		if system.tag.read(tagName):
			system.tag.write(tagName, 0)
		else:
			system.tag.write(tagName, 1)

```

But it doesn’t get past `here 1` and the error that gets logged is `global name 'self' is not defined`. Any thoughts? I don’t know whats going on.

The alternative here I guess would be to feed the session itself to the very first and every subsequent function with a `session=None` keyword argument I guess right?
