# Broadcast message to all open session

**URL:** <https://forum.inductiveautomation.com/t/broadcast-message-to-all-open-session/80735>\
**Category:** Ignition\
**Created:** [October 20, 2023, 12:52am UTC](https://forum.inductiveautomation.com/t/broadcast-message-to-all-open-session/80735 "2023-10-20T00:52:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [October 20, 2023, 12:52am UTC](https://forum.inductiveautomation.com/t/broadcast-message-to-all-open-session/80735/1 "2023-10-20T00:52:53Z")

</div>

I saw many threads on `system.util.sendMessage`.  
But really, how do you properly broadcast message to all open sessions?

I have a button that inserts new record on database.  
After insert, I want to refresh table on all open sessions.  
What are the steps to accomplish this?

Fwiw, `system.util.sendMessage` has "project" argument where you specify the name of the project where the recieving "message handler" resides. Then what is the "scope" argument for?

Thanks.

---

<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:** [October 20, 2023, 1:48am UTC](https://forum.inductiveautomation.com/t/broadcast-message-to-all-open-session/80735/2 "2023-10-20T01:48:41Z")

</div>

You have to remember that an individual project may have multiple types of Sessions open against it. If you have a project named `Demo`, and you have both Vision AND Perspective pieces to that project, you can use the scope to dictate which pieces get a given message.

```auto
system.util.sendMessage("Demo", "MyMessageHandler", scope="C")

```

Would send the message to all Vision clients, while no Perspective Sessions would hear the broadcast.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [October 20, 2023, 2:30am UTC](https://forum.inductiveautomation.com/t/broadcast-message-to-all-open-session/80735/3 "2023-10-20T02:30:29Z")

</div>

Sounds good.  
If I need to broadcast message to all open sessions, on the same project.

How would you do it?  
Can you use both `system.perspective.sendMessage` and `system.util.sendMessage` to accomplish this?

---

<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:** [October 20, 2023, 2:56am UTC](https://forum.inductiveautomation.com/t/broadcast-message-to-all-open-session/80735/4 "2023-10-20T02:56:33Z")

</div>

To broadcast to all open sessions on the same project, you would do this:

```auto
system.util.sendMessage("Demo", "MyMessageHandler", scope="CGS")

```

Only use `system.perspective.sendMessage()` within Perspective areas (Views, Event scripts, onChange scripts) as it needs to be invoked on a Perspective thread in _almost_ every case.

Keep in mind that the _Session_ (NOT the Page or View) will hear the broadcast message, but then the Session needs to take further action. Invocations of `system.util.sendMessage()` which target Perspective Sessions typically are heard by a Perspective Session Message Handler, which then in turn invokes `system.perspective.sendMessage()` to dictate what should be done with the message.

Think of it like ordering a pizza (back in the day):  
You call the pizza place and tell the person on the phone you want a pizza. That person doesn't make the pizza - they take your order and then pass it to the people in the back. Message handling works in the same manner, where the Session Message Handler answers the phone and then sends the message along to a better-defined scope.

---

<div class="post-metadata">

**Author:** ![Eugene49](https://avatars.discourse-cdn.com/v4/letter/e/c6cbf5/32.png) [@Eugene49](https://forum.inductiveautomation.com/u/Eugene49)\
**Post date:** [October 20, 2023, 8:16pm UTC](https://forum.inductiveautomation.com/t/broadcast-message-to-all-open-session/80735/5 "2023-10-20T20:16:15Z")

</div>

That Worked! Thanks.

On Trigger Button:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/4/746fb3d96de0dfd06520a159fed71aad87701f11.png)

On Project-\>Session Events -\> Message:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/1/01b83208c00b39efb9f3c5a1f691149bb781af5d.png)

On View-\>Root-\>Script:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/e/2ee72d75054cc35bb793c3189f671d2385a087bd.png)

I tested via two PC. Message was well received on Both PC.
