I have prepared a script on the tag level (value changed) type to close a perspective popup page called "popup". The script is trying to close the popup after the previousvalue of the tag is true and currentvalue is false.
But it seems the popup window does not close, not sure why.
attaching the snapshot of the script below to have a look.
Thanks
Surjit
system.perspective.closePopup()
takes a popup id, not a view name.
Consider the popup action screen below, the string you need to pass into the method is the string that you specify in the "Identifier" section in this dialog.
This is set whenever you call a popup to open, from both scripting and GUI methods.
Yes, thats correct, i already have the popup id specified as "popup".
However it doesnt seem to work.
I even used the onDataChange to check the value change but still doesn't work.
It definitely works on an event eg. onActionPeformed, but doesn't seem to work during value change.
Regards
Surjit
I am going to assume there is a scope issue here, all the "onActionPerformed" events are session scoped, but the tag change scripts are gateway scoped.
I would set up a message handler in a session script to receive a message from the gateway scoped script on the tagChange event, and close any popups in that session with the id "popup". That way you are going to get away from scope limits.
You had created this thread in "Automated Testing" but there is no mention of this in the post. I've moved it to "Ignition" where it will get more attention.
1 Like
Popups and tags do not live in the same scope. You can't close a popup from the gateway. Not directly.
The simplest way of implementing this would be to add a custom property to your popup, bind it to the tag, and add a change script to that property. Then you can close the popup from that change script.
If the popup is not specific to this use case and you need it to be a bit more reusable, it can be done, let us know if that's the case.
1 Like
You can actually, but the invocation needs context. Tags live on the Gateway, and you're trying to close a Popup in some client browser Session. Beyond that, the Popup lives on a page (or pages) of the Session. Suppose more than one Session had more than one of these Popups open. Which should be acted on?
For Gateway Events - I'm including Tags in this - system.perspective
calls almost always must have the pageId
argument supplied. This argument clearly tells the Gateway which page should be acted upon.
If you look at your Gateway you'll find logging along the lines of "No Perspective page attached to thread" This is how system.perspective.*
invocations which require more context (pageId
) inform you that more information is needed.
Alternatively, you could use system.util.sendMessage (with a scope of "S") to send a message to ALL Perspective Sessions, and allow the Sessions to determine what to do with that information by supplying logic in your own handler at the Session level.
3 Likes
on the gateway I have created a gateway event using the system.util.sendMessage to send the message handler with scope "S".
But this doesn't seem to close the popup when the tag value changes.
Below snapshot from the gateway script:

Below snapshot from the Message handler:
This canât work, thatâs not how functions work, or what the payload is for.
Iâm on a phone so not the best situation to type code, but Iâll try to explain whatâs wrong and how to fix it.
First things first: what your code actually does.
Youâre calling the closePopup function in the tag event script, which is exactly what the whole thing is trying to avoid. Whether youâre calling it in the payload definition or not doesnât change the scope in which it is executed.
What it does here is call a function (letâs put aside the fact that the call fails) and send the value returned by this call with the payload.
Then the message handler just accesses this value. Thereâs no closing done by the message handler.
You could send a function path through the payload and call it in the handler, but itâs really not necessary here. It would look something like this:
# payload definition in the event script
payload = {
âclose_funcâ: system.perspective.closePopup,
âpopup_idâ: âsome_idâ
}
# call in the handler
payload[âclose_funcâ](payload[âpopup_idâ])
Note where the parentheses are: the function is not called in the event script, but in the message handler. But thatâa really not how you should be doing it anyway, the point here is just to illustrate what was wrong.
You need to call the closePopup function in the session scope, which is why youâre sending a message. You can have message handlers in the session scope, and call the function from there.
Also note that the message handlerâs name is case sensitive, so you will have to fix that too: make the name on both sides match exactly.
3 Likes
Beyond just the points that @pascal.fragnoud has raised, broadcasting with system.util.sendMessage(... scope="S")
will be heard by a SESSION - not a Page or Component. To have a Component take any action, the Session must act as a go-between, re-broadcasting the message as is appropriate for the Session.
Tag:
# Broadcast message to be heard by ALL Sessions
system.util.sendMessage(... scope="S")
Session Message Handler:
# Broadcast to the the entire session.
# Note that the scope here is a full word - not a letter.
system.perspective.sendMessage(... scope="session")
Component Message Handler:
# Listening at the Session scope is mandatory here.
system.perspective.closePopup('popup')
This could also be simplified depending on your use-case. Is your expectation that every Popup with an ID of popup
be closed across all Sessions? What are the conditions to determine which Popups are closed? Since it's a Tag, I'm going to assume it's all Sessions.
# pseudo-code
# This should close all Popups with an id of "popup" across all pages in all sessions
for session in system.perspective.getSessionInfo():
for pageId in session.pageIds:
system.perspective.closePopup('popup', sessionId=session.id, pageId=pageId)
3 Likes
Thank you everyone, both the solutions provided above are really appreciated.
I have actually got it resolved, but in a little bit different method. Below is what I did in case others visiting the page may get some more information:
- I used a Button component and used indirect binding to bind the custom parameters (PARAMS): "Tagpath" and Boolean "State" of the tag on the "enabled" property of the Button component.
- Since i have already configured indirect binding on the "enabled" PROPS of the Button component, I used the "Edit Change Script" option available on the "enabled" property, available on right clicking it.
- In this "Edit Change Script" of the component property, I used the below script to close my pop-up page when the value of the binded indirect tag changes, snapshot below:
Regards
Surjit Huidrom
1 Like