Opening a Popup from a Session Message Handler

Hi Everyone,

I am attempting to open a Popup from a Session Message Handler with no luck.

For testing purposes, I have set up a button on a view, when "onActionPerformed" has the following script associated:

sessionid = self.session.props.id
	
system.perspective.sendMessage("breakStartPopup", payload={"someValueKey": "SomeActualValue"}, clientSessionId = sessionid, scope = "session")

The Session Message Handler is setup up as the following:

If I run this "system.perspective.openPopup" command directly on the button it works, but when trying to invoke it using the Session Message Handler, nothing happens.

Any help or guidance to get this to work would be greatly appreciated.
Thank you in advance

Skeptical about path view="/Popups/BreakPrompt" :cross_mark:
Should be view="Popups/BreakPrompt" :white_check_mark:

The code you show uses a session variable, but it's not defined.

I'm pretty sure that if you read your logs, you'll see something along the lines of "NameError: session is not defined"

What exactly are you trying to do ?

Sire it is, it's provided by the msg event. But this is the entire object, should be getting the id from it as that's what the sessionId param is after

Oh, right. Never used that ;p

Well, I still believe that session parameter passed to openPopup is the source of the issue, though now I can't tell what error would appear in the logs.
The sessionId parameter shouldn't be needed anyway, it should default to the current session... right ?

Yes. It should just be omitted unless it's a Gateway Message handler, then it must be included because of this:

[1]This function will only work in the Gateway scope if both sessionId and pageId are supplied to the call.

Personally, I'm a little confused as to why a message handler needs to be used here at all. Just use system.perspective.openPopup() Even if you're going to be brodcasting to all active sessions, you don't need a message handler.


  1. â†Šī¸Ž

? This is exactly when you would need to use sendMessage and have messages handlers

No, it isn't. system.perspective.openPopup() can target a page in a session if you hand it the session ID and page ID in keyword arguments. This can be called from gateway scope outside Perspective scope.

1 Like

Oo, I stand corrected. I guess I've never used it like that. Good to know!

Hi Everyone,

I worked out what to do to invoke this.

I ended up using "system.util.sendMessage()" instead of "system.perspective.sendMessage()", parsing the "sessionId" and "pageId" in a payload, and using those parameters in the "system.perspective.openPopup()" within the Session Message Handler.

Just for reference, see screenshots of working code:

Script for "onActionPerformed" event on Button:

Script for Session Message Handler (breakStartPopup):

I hope this can help anyone in the future.

Note:
I used the following link which really helped getting to this solution - Perspective Session Event Scripts | Ignition User Manual