# system.util.sendMessage() perspective scripting

**URL:** <https://forum.inductiveautomation.com/t/system-util-sendmessage-perspective-scripting/38799>\
**Category:** Ignition Early Access\
**Tags:** perspective, ignition80\
**Created:** [September 17, 2020, 2:33pm UTC](https://forum.inductiveautomation.com/t/system-util-sendmessage-perspective-scripting/38799 "2020-09-17T14:33:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [September 17, 2020, 2:33pm UTC](https://forum.inductiveautomation.com/t/system-util-sendmessage-perspective-scripting/38799/1 "2020-09-17T14:33:47Z")

</div>

I have a script that calls system.util.sendMessage(). When scope is not provided (default: GCS) I get a return value of:[type=Gateway,project=myProject,messageHandler=test,filterParams={userRoles=, userZones=},isRequest=no,sendStatus=SENT] as expected

However, the message handler in the Gateway Events or Session Events is not triggered. Also, the gateway message handler has a last executed status of ‘Never’ on the Gateway home page under Status\>Systems\>Gateway Scripts.

Additionally, when scoping the message to ‘S’ I do not get a return value (e.g. system.util.sendMessage() = []).

I can confirm that the project name and the message handler identifier are correct. There are also no errors in the status logs as far as I can see.

Is there anything you can advise that I have probably missed, or is this a bug?

Tested on 8.0.16 & 8.1.0RC1

---

<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, 2:43pm UTC](https://forum.inductiveautomation.com/t/system-util-sendmessage-perspective-scripting/38799/2 "2020-09-17T14:43:00Z")

</div>

Could you provide the snippet of code which actually invokes the `sendMessage` call? Could you also provide a screenshot of the Session Event Message Handler for the `myProject` project with a handler name of “test”?

---

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [September 17, 2020, 3:16pm UTC](https://forum.inductiveautomation.com/t/system-util-sendmessage-perspective-scripting/38799/3 "2020-09-17T15:16:42Z")

</div>

Hi @cmallonee

As requested, code snippet:

```auto
ret = system.util.sendMessage(project='myProject',messageHandler='test')
system.perspective.print(ret)

```

Screenshot:

 ![SessionEventMH](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/d/cdcde530467b1de6b53896cfaa581517d7ebfd1f.jpeg)

Thank you for your help, I’m still relatively new to the Ignition world, so I’m not sure if I’ve missed something obvious.

---

<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, 6:27pm UTC](https://forum.inductiveautomation.com/t/system-util-sendmessage-perspective-scripting/38799/4 "2020-09-17T18:27:00Z")

</div>

I like to play a game called Good News/Bad News:

Good News:  
This is working for me, with one small caveat - Sessions which “hear” the broadcast are not reporting as having heard the broadcast (which is why you’re getting an empty array).

Bad News:

1. You SHOULD see an error in your Gateway logs because you may not use `system.perspective.print()` in a Session Message Handler as you have it configured. That function requires a page context behind-the-scenes (it needs to know where it’s printing to) but that function is being invoked on the Gateway - which has no pages. You could pass a pageId as part of the payload of the `system.util.sendMessage()` call, or you could switch to using `system.util.getLogger('MYLOGGER').info('message passed'))`
2. Designers don’t truly count as open sessions for the purposes of this function. Essentially, Designers don’t listen for messageHandlers. If you were to open a true Session to a Page/View which contains a component with “test2” configured as a Message Handler and you print some sort of receipt statement, then you’ll see that the message is coming through.

---

<div class="post-metadata">

**Author:** ![matthew.ayre](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matthew.ayre/32/19499_2.png) [@matthew.ayre](https://forum.inductiveautomation.com/u/matthew.ayre)\
**Post date:** [September 21, 2020, 9:49am UTC](https://forum.inductiveautomation.com/t/system-util-sendmessage-perspective-scripting/38799/5 "2020-09-21T09:49:36Z")

</div>

@cmallonee thank you for pointing me in the right direction.

> [@cmallonee](#):
>
> ...that function is being invoked on the Gateway - which has no pages

This was the line that completed the puzzle in my head. I will also keep in mind the requirements for `system.perspective.print()`.

For the other newbies like myself, and building on what has already been said, if you are passing the message on via `system.perspective.sendMessage()`, scope is also important unless passing the appropriate pageId. (Please correct me if I'm wrong)

---

<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 21, 2020, 3:34pm UTC](https://forum.inductiveautomation.com/t/system-util-sendmessage-perspective-scripting/38799/6 "2020-09-21T15:34:52Z")

</div>

So, scope in this situation is a little tricky, but you have options. You could either supply a scope of 'session" and allow the “broadcast” to be heard by all Pages/Views in all Sessions (because you haven’t filtered this in any way at this point), or you could specify a scope of “page”. If you specify a scope of “page”, however, you MUST supply a `sessionId` argument as well, which means that you need to already know the session you want to target (potentially passed as part of the payload), or you need to supply logic to locate valid sessions which meet some sort of logical condition using [system.perspective.getSessionInfo()](https://docs.inductiveautomation.com/display/DOC80/system.perspective.getSessionInfo). So scope is important, even if you supply a `pageId` - supplying that argument does not mean that we will locate an appropriate Page from available Sessions.
