# Reading Session Properties in Script

**URL:** <https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [April 12, 2019, 7:31pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109 "2019-04-12T19:31:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [April 12, 2019, 7:31pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109/1 "2019-04-12T19:31:54Z")

</div>

I’m trying to read the authenticated session property in a script to determine if a button will be log in or log out. In the expression for the text, the binding was easy, but the script is proving to be a bit more challenging. What I have so far is below, but the getProperty script is returning ‘None’ and I tried without get property and it said it couldn’t find session.

```auto
	auth = system.util.getProperty("session.props.auth.authenticated")
	log=system.util.getLogger("Test Log")
	log.warn("%s"%auth)

	if(auth == 'true'):
		system.perspective.logout()
	else:
		system.perspective.login()

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 12, 2019, 7:33pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109/2 "2019-04-12T19:33:08Z")

</div>

`auth = self.session.props.auth.authenticated`

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [April 12, 2019, 7:34pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109/3 "2019-04-12T19:34:19Z")

</div>

> [@cmallonee](#):
>
> session.props.auth.authenticated

Script doesn't run with that option.

```auto
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 2, in runAction NameError: global name 'session' is not define

```

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 12, 2019, 7:35pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109/4 "2019-04-12T19:35:46Z")

</div>

Sorry, I skipped the “self.” part.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 12, 2019, 7:37pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109/5 "2019-04-12T19:37:18Z")

</div>

Also, you’ll want to have something more like

```auto
    auth = self.session.props.auth.authenticated
	log=system.util.getLogger("Test Log")
	log.warn("%s"%auth)

	if auth:
		system.perspective.logout()
	else:
		system.perspective.login()

```

because the value comes back as a `bool` - not a `str`.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [April 12, 2019, 7:37pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109/6 "2019-04-12T19:37:59Z")

</div>

That was it. Thanks.

Wasn’t sure what was the route to get up to session properties. I had tried adding a couple of parent levels in there last time and that didn’t work. For some reason skipped just ‘self.’

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 12, 2019, 7:38pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109/7 "2019-04-12T19:38:56Z")

</div>

`self.parent.session` should still have worked… I believe each component/container has a concept of “session”.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [April 12, 2019, 7:41pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109/8 "2019-04-12T19:41:34Z")

</div>

> [@grietveld](#):
>
> Wasn’t sure what was the route to get up to session properties. I had tried adding a couple of parent levels in there last time and that didn’t work. For some reason skipped just ‘self.’

Hmm...so it does. Must have had a typo when I tried just one parent level.

It does error if I do parent.parent since that is too many levels up. Guess my brain has already turned off for the weekend.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 12, 2019, 7:43pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109/9 "2019-04-12T19:43:46Z")

</div>

it depends on the depth you’re calling/invoking from; if you are invoking from a component placed in a root container, then `self.parent.parent` would error out because the root container has no parent.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [April 12, 2019, 7:45pm UTC](https://forum.inductiveautomation.com/t/reading-session-properties-in-script/24109/10 "2019-04-12T19:45:12Z")

</div>

Yeah, I was thinking parent would be the container, then parent of that might be the session when I had tried that. Which was not the case.
