# Tag change script not sending to message handler

**URL:** <https://forum.inductiveautomation.com/t/tag-change-script-not-sending-to-message-handler/30542>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 9, 2019, 3:15pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-sending-to-message-handler/30542 "2019-12-09T15:15:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![omarin](https://avatars.discourse-cdn.com/v4/letter/o/e56c9b/32.png) [@omarin](https://forum.inductiveautomation.com/u/omarin)\
**Post date:** [December 9, 2019, 3:15pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-sending-to-message-handler/30542/1 "2019-12-09T15:15:27Z")

</div>

Hi everybody,

I’m trying to send a message to a perspective session for delogging session user.  
From a boolean tag, I create a tag change script

```
project = "FX"
scope = "CP"
messageHandler = "logout"
system.util.sendMessage(project,messageHandler,{},scope) 

```

In a perspective view, I create a message handler named “logout”  
listen scope is Session and View  
script is only  
system.perspective.logout()

When changing the boolean tag, nothing happens

I also create a small button on the view, on configure event/onclick/script  
system.perspective.logout() is logging out the perspective session

What can I be missing in my message handler properties ?

Thank you

---

<div class="post-metadata">

**Author:** ![md.szyman](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/md.szyman/32/9240_2.png) [@md.szyman](https://forum.inductiveautomation.com/u/md.szyman)\
**Post date:** [December 9, 2019, 3:49pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-sending-to-message-handler/30542/2 "2019-12-09T15:49:21Z")

</div>

I don’t believe that a Perspective view handler can receive messages from a Tag Change script as they are Gateway scoped.

---

<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:** [December 9, 2019, 4:36pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-sending-to-message-handler/30542/3 "2019-12-09T16:36:23Z")

</div>

Perspective doesn’t (yet) support message handling - you can send a message at the gateway level, but you aren’t able to receive that message in a Perspective session. The functionality should be available pretty soon, though - keep an eye on the nightly changelogs.

---

<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:** [December 10, 2019, 12:03am UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-sending-to-message-handler/30542/4 "2019-12-10T00:03:17Z")

</div>

1. `system.util.sendMessage` has no defined scope of “CP”. You could use “CG”, but you don’t need to send a scope either.
2. `messageHandler` in this context is the GATEWAY message handler, NOT the Perspective **messageType**.
3. You might think that you could just switch over to `system.perspective.sendMessage`, but you can’t because tags have no concept of session.

Others have commented that perspective can’t receive messages form tags, and they’re correct, but you CAN send a message to the gateway, and the Gateway can send messages to sessions, BUT this all seems more complicated than it needs to be.

What you SHOULD do is bind a session property to a tag, something like `session.custom.logUserOut` to a tag path of “[tagProvider]/users/userName/logUserOut”.  
Apply a property change script to the session property with the following code:

```auto
if currentValue.value is not None and currentValue.value:
    system.perspective.logout()

```

---

<div class="post-metadata">

**Author:** ![omarin](https://avatars.discourse-cdn.com/v4/letter/o/e56c9b/32.png) [@omarin](https://forum.inductiveautomation.com/u/omarin)\
**Post date:** [December 10, 2019, 7:39am UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-sending-to-message-handler/30542/5 "2019-12-10T07:39:27Z")

</div>

Regarding the “CP” scope, from the user manual the system.util.sendMessage indicates that his scope can be as follow

- Scope

Gateway, Vision Client, Perspective Session

But the Perspective Session was not documented so I tried to imagine what can it be regarding the previous logic

I will try your solution  
Thank you for your quick responses,

---

<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:** [December 10, 2019, 2:57pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-sending-to-message-handler/30542/6 "2019-12-10T14:57:28Z")

</div>

From the [docs](https://docs.inductiveautomation.com/display/DOC80/system.util.sendMessage):

String scope - Optional. Limits the scope of the message delivery to "C" (clients), "G" (Gateway), or "CG" for clients and the Gateway. Defaults to "C" if the user name, role or host name parameters are set, and to "CG" if none of these parameters are set.

> [@omarin](#):
>
> But the Perspective Session was not documented so I tried to imagine what can it be regarding the previous logic

I wouldn't recommend that. If something isn't documented, then you're probably using it incorrectly. In this case, scope has two different meanings/definitions between `system.util.sendMessage` and `system.perspective.sendMessage`. The util function scope argument determines where the message gets sent to, while the Perspective scope argument determines the level of hierarchy which may "hear" the message.

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [September 17, 2020, 8:32pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-sending-to-message-handler/30542/7 "2020-09-17T20:32:45Z")

</div>

Any update on that

---

<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 17, 2020, 8:36pm UTC](https://forum.inductiveautomation.com/t/tag-change-script-not-sending-to-message-handler/30542/8 "2020-09-17T20:36:32Z")

</div>

We’ve since introduced a way to use [system.util.sendMessage](https://docs.inductiveautomation.com/display/DOC80/system.util.sendMessage) where you can specify Perspective Sessions by supplying “S” as part of the scope.
