# \[IGN-6563\]Retrieve Session custom props remotely

**URL:** <https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 7, 2022, 4:26pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840 "2022-09-07T16:26:22Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [September 7, 2022, 4:26pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/1 "2022-09-07T16:26:22Z")

</div>

I know that with `system.perspective.getSessionInfo()` you can get some generic session information. However is it possible to get perspective session custom props remotely?

I have synced them to the database in the past, but I am looking for a solution that is a bit more elegant.

I appreciate any info!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 7, 2022, 4:47pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/2 "2022-09-07T16:47:38Z")

</div>

Perhaps using `system.util.sendRequest()` to return them from the project?

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [September 7, 2022, 4:52pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/3 "2022-09-07T16:52:58Z")

</div>

I thought about that, but I wasn’t sure how I would get the session props out of the project scope either.

---

<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:** [September 7, 2022, 4:58pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/4 "2022-09-07T16:58:03Z")

</div>

Session custom props are unique to a particular running session, so you would need to pass a particular session ID.

If you have something truly ‘global’, then it would probably be better off living in `system.util.getGlobals()` than a session custom property?

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [September 7, 2022, 5:08pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/5 "2022-09-07T17:08:06Z")

</div>

> [@paul-griffith](#):
>
> so you would need to pass a particular session ID.

I am actually open to this, but I can't figure out where to send a sessionId to get its props.

> [@paul-griffith](#):
>
> If you have something truly ‘global’, then it would probably be better off living in `system.util.getGlobals()` than a session custom property?

Maybe some clarification on what I am trying to do would help. I am trying to get the session props for remote monitoring of a specific session. That way I can see debug details about a users session remotely, without needing to sync them all into a database. Ideally a `system.perspective.getSessionInfo(id=sessionId)` would be great but it doesn't provide the custom props. Or even a `system.util.sendRequest(projectName, "getSessionProps", sessionId=sessionId)` would be fine, maybe easier to provide them to the gateway scope. However I can't find any way to send a request directly to a session, or just do a lookup on those props by their ID from the gateway scope.

EDIT: One way to do this would be by putting them in the globals with a `WeakRef` key that is a reference to the session, but you can't grab the true session reference because of the safety wrappers 🙁, so you risk memory leaks if things aren't cleaned up correctly.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 7, 2022, 5:27pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/6 "2022-09-07T17:27:03Z")

</div>

How about a really hacky way to do it?

`system.util.sendMessage(projectName, "requestSessionProps", {callBackServer=remoteServerAddress, sessionId=sessionId})`

Then in the `requestSessionProps` handler call `system.perspective.sendMessage('getSessionProps',{server=remoteServerAddress}, 'S',sessionId)` to a handler in the session, which packages the custom props and uses `system.util.sendMessage()` to return the props?

Not sure I would call that elegant, but it might work.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [September 7, 2022, 6:12pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/7 "2022-09-07T18:12:17Z")

</div>

> [@lrose](#):
>
> system.util.sendMessage(projectName, "requestSessionProps", {callBackServer=remoteServerAddress, sessionId=sessionId})

Okay, so this does work, it's dirty, but it technically works.

Digging around in this I found that the documentation says that the documentation says `system.util.sendRequest` is a valid caller for Session Message Handlers:

> The Message Handler scripts will run whenever the Session receives a message from [system.util.sendMessage](https://docs.inductiveautomation.com/display/DOC81/system.util.sendMessage) or [system.util.sendRequest](https://docs.inductiveautomation.com/display/DOC81/system.util.sendRequest).

However the `clientSessionId` and `scope` params don't seem to be valid kwargs for `system.util.sendRequest`. Is this a documentation error or potentially a bug? (I really hope the answer is fixable bug, because that solves my problem the best lol)

---

<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:** [September 7, 2022, 6:21pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/8 "2022-09-07T18:21:56Z")

</div>

The intention in the code appears to be that a `sessionId` or `clientSessionId` kwarg will both be accepted by both functions and do the ‘right’ thing in Perspective.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [September 7, 2022, 6:28pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/9 "2022-09-07T18:28:06Z")

</div>

Looks like there may be a bug unless I have something wrong here

### My Caller (On a perspective button for testing):

```python
sessionId = self.session.props.id
response = system.util.sendRequest(project="MES", messageHandler="getSessionProps", payload={}, scope="S", clientSessionId=sessionId)

```

### The Message Handler (getSessionProps)

```python
system.util.getLogger("SessionProps").info("Request Received: %s" % (session.custom))
return session.custom

```

### The Exception:

```python
Error running action 'component.onActionPerformed' on Test@D/root/Button: Traceback (most recent call last): File "<function:runAction>", line 3, in runAction at com.inductiveautomation.ignition.common.script.message.MessageHandlerManager.processRequest(MessageHandlerManager.java:195) at com.inductiveautomation.ignition.common.script.ScriptConfig.invokeGWRequestHandler(ScriptConfig.java:242) at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle.dispatchScriptMessage(ProjectScriptLifecycle.java:552) at com.inductiveautomation.ignition.gateway.project.IgnitionProjectManager.invokeGWMessageHandler(IgnitionProjectManager.java:189) at com.inductiveautomation.ignition.gateway.clientcomm.scriptmsg.MessageDispatchManagerImpl.doGatewayNotification(MessageDispatchManagerImpl.java:538) at com.inductiveautomation.ignition.gateway.clientcomm.scriptmsg.MessageDispatchManagerImpl.dispatchLocal(MessageDispatchManagerImpl.java:338) at com.inductiveautomation.ignition.gateway.clientcomm.scriptmsg.MessageDispatchManagerImpl.dispatchRequest(MessageDispatchManagerImpl.java:204) at com.inductiveautomation.ignition.gateway.script.GatewaySystemUtilities.sendRequestInternal(GatewaySystemUtilities.java:288) at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.sendRequestInternal(SystemUtilities.java:907) at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.sendRequest(SystemUtilities.java:828) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) com.inductiveautomation.ignition.common.script.message.MessageHandlerException: com.inductiveautomation.ignition.common.script.message.MessageHandlerException: The message handler "getSessionProps" could not be found! Check your event script message handlers.

```

Here is the project export:  
[SendRequestProject.zip](https://forum.inductiveautomation.com/uploads/short-url/1FQCXlePuPhuofP7nlMRk8k5Zlj.zip) (6.1 KB)

---

<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:** [September 7, 2022, 8:42pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/10 "2022-09-07T20:42:47Z")

</div>

it looks like you might have tried something similar to this before, but it’s not clear why it didn’t work for you.

From a Button in the session requesting props:

```auto
system.util.sendMessage("<ThisProjectName>", "REQUEST_PROPS", payload={"requestSessionId": self.session.props.id}, clientSessionId="<someTargetSessionid>", scope="S")

```

Message Handler (`REQUEST_PROPS`)

```auto
props_object = {}. # build out what you want to send back here.
system.util.sendMessage("<ThisProjectName>", "RECEIVE_PROPS", payload=props_object, clientSessionId=payload["requestSessionId"], scope="S")

```

Then you just need a second handler (`RECEIVE_PROPS`) for processing the props returned from `REQUEST_PROPS`.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [September 7, 2022, 8:46pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/11 "2022-09-07T20:46:53Z")

</div>

> [@cmallonee](#):
>
> it looks like you might have tried something similar to this before, but it’s not clear why it didn’t work for you.

A back and forth `sendMessage` did work it was just a bit dirtier, and lacked some of the determinism of a `sendRequest`. The issue was primarily that `sendRequest` was documented to work as well, and it seems it doesn't work as expected. Being able to put a `sendRequest` on a custom prop would make it much easier to put together a screen that does what I want in retrieving client session details.

---

<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:** [September 7, 2022, 10:07pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/12 "2022-09-07T22:07:03Z")

</div>

Oh. You’ve set up getSessionProps as a SESSION Event message Handler, but it needs to be a GATEWAY Event message handler.

This is going to render `sendRequest` useless because you’re now out of the Session scope.

Update: I see you’ve referenced a part of the Docs which claims that sendRequest should trigger Session Events as well, but… this is news to me. I’ve never tried that and to my knowledge we have no testing to confirm this. I’m looking into it.

---

<div class="post-metadata">

**Author:** ![hunterdg](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hunterdg/32/67774_2.png) [@hunterdg](https://forum.inductiveautomation.com/u/hunterdg)\
**Post date:** [February 23, 2024, 10:06pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/13 "2024-02-23T22:06:06Z")

</div>

> [@cmallonee](#):
>
> I’m looking into it.

I also have a use-case for bidirectional/inter-session communication and I'm assuming (perhaps incorrectly) from **[IGN-6563]** in the subject that this became a bug/support ticket - any chance there's been a resolution?

---

<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:** [February 23, 2024, 10:09pm UTC](https://forum.inductiveautomation.com/t/ign-6563-retrieve-session-custom-props-remotely/63840/14 "2024-02-23T22:09:27Z")

</div>

6563 is an internal feature ticket that hasn't yet been picked up.  
The gist of the ticket is "make it possible to do more dynamic/meta stuff in Perspective, via scripts and expressions". Stuff like returning the view's own ID via `{view.id}`, or get a 'live' session object given the ID via some `system.perspective.getSession()` function. Stuff like that should act as 'building blocks' to allow functionality more like what you're looking for on top.
