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.
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.
system.util.sendMessage("Demo", "MyMessageHandler", scope="C")
Would send the message to all Vision clients, while no Perspective Sessions would hear the broadcast.
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?
To broadcast to all open sessions on the same project, you would do this:
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.
2 Likes
That Worked! Thanks.
On Trigger Button:

On Project->Session Events -> Message:
On View->Root->Script:

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