[SOLVED] Open window in script tag changed

Hello everyone, I want to open a window after a tag value change inside the script tag but did not work and I tried changing manually the tag while running the project, can anyone help me please?

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	Fired whenever the current value changes in value or quality.

		tag: The source tag object. A read-only wrapper for obtaining tag
		tagPath: The full path to the tag (String)
		previousValue: The previous value. This is a "qualified value", so it
		               has value, quality, and timestamp properties.
		currentValue: The current value. This is a "qualified value", so it has
		              value, quality, and timestamp properties.
		initialChange: A boolean flag indicating whether this event is due to
		               the first execution or initial subscription.
		missedEvents: A flag indicating that some events have been skipped due
		              to event overflow.
	if previousValue.value != currentValue.value:
		system.nav.openWindowInstance("User Management/mensajeAlarma")

Is this a custom method on a component that is bound in some way to the tag?

Edit: Disregard; I see now what you are saying

Unless this is a client-scoped tag change script, your execution context is wrong and this will never work.
A tag running on the gateway does not ‘know’ which client you are attempting to open a window instance on.

So , when the tag change, needs to open the window

And am I have to run the project in the client or can I with the gateway only?

You need to decide what happens and where.
Does every single open client need to react to this tag changing, or a particular one? Or only one opened by an administrator, or some other requirement?

If every client needs to react to some tag changing, then you need a client-scoped tag change event. See the manual page I linked earlier. That will make every open client automatically “watch” the tag you supply, and as soon as it changes, run your script.

If you want every client to see the pop-up on a tag change, then, I believe this is what you are wanting to do:
Example Part 1

Thank you so much

Thank you so much for the help, it worked

Hello, It worked, when the tag change the window instance is open but if there is more than one window open, if I apply a clic inside my principal window, the instance disappear → For example:
The number 1 is my instance and the number 2 is the principal window, so when I do a clic in the principal window, the number 1 disappear

and I want it fixed as stay there until I close the window, because has a button that close the window.


In my attempt to recreate the problem, I’ve taken the following steps:

  • I created a Boolean tag called Test Tag, and popup window called Popup.
  • Then, I set up a tag change client event script to open the popup if the tag changes state.

When I launch the project and subsequently change the Boolean value, the popup opens as expected, but when I click on the main window, causing the popup to loose focus, the popup doesn’t close as you are describing.

Is it possible that you have a script on the main window or the popup itself that is automatically closing the popup when it looses focus?

Look at your project browser, and check to see if there is any scripting:

Look for something like this:

I found that I was using a Main window and I changed to a pop up as should be, that is why, and not , I don’t have any script that is closing automatically the window.

But now are happening two things:

  1. If I have 3 instances of pop up window open, so I am located at the third pop up that opened and if I clic on other pop up, both windows will have the same values in the labels and I don’t want that because I need to stay the different values in each pop up.

  2. When I try to close the third pop up (as in this example), only close the first one , then the second and at the final the third pop up. →

So I have this order where the first one is the last pop up that opened:

3 (third) window-pop up - last to open
2 (second) window-pop up
1 (first) window-pop up - first to open

I choose close the third and is closing the windows in the next order.
1,2,3 when I need to close the pop up that I choose .

I have a question, because followind my code:

if event.getCurrentValue().getValue()!=event.getPreviousValue().getValue():
	if event.getCurrentValue().getValue():
		system.nav.openWindowInstance("User Management/mensajeAlarma")

I got this error :
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1687)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:806)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:752)
at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:241)
at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:193)
at com.inductiveautomation.ignition.common.util.SerialExecutionQueue$PollAndExecute.run(SerialExecutionQueue.java:102)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException: AttributeError: ‘NoneType’ object has no attribute ‘getValue’

getPreviousValue can return null if the initialChange flag is set:

If your tag is Boolean [True, False], then you can simplify your code to this:

if event.getCurrentValue().value:
	system.nav.openWindowInstance("User Management/mensajeAlarma")

That will eliminate the problem.

The tag is String because is a Tag memory and in some part of the project something write to the memory tag.

To complete this thread, there were three additional problems listed that either have been solved, or are close to being solved:

Problem 1:

This was being caused by the population script being fired from the internalFrameActivated event handler which is triggered anytime a window gains focused. It was fixed by moving the script to the internalFrameOpened event handler which only gets launched when the window is initially opened, and is subsequenly never triggered again.

Problem 2:

The cause of this was that the script for closing the window was using the ambiguous path/window name for the close command. system.nav.closeWindow("Path/windowName") Since each window instance had the same path and name, there was no guarantee that the intended window would close. This was fixed by using the following script instead:

window = system.gui.getParentWindow(event)

This script identifies which window that the event originated from, and then closes that specific window.

Problem 3:
The client tag change event script was producing the following error:

I’m not sure if this is solved yet or not, but the way the code was written, the popup would have launched at start up whether or not the string had changed. Furthermore, the tag in question was a string datatype, and in the second if statement, the string was being treated like a bool, so I imagine that this would probably not work as intended. As @PGriffith suggested, the code should probably be written like this:

if event.getPreviousValue() is not None and event.getCurrentValue()!=event.getPreviousValue():
	system.nav.openWindowInstance("User Management/mensajeAlarma")

In this way, the popup will not be triggered during the startup event, but will be triggered during any subsequent tag change.

Problem 1: Solved
Problem 2: Solved, I was just closing the window
Problem 3: It worked, but if the tag at the first when the last value went :
Label1 | Label 2
02 | 07

Then the tag change to for the first time to->
Label1 | Label 2
09 | 07

The pop up appears with :
Label1 | Label 2
02 | 07

So the value of the label 1 is the previous value and is not changing to the current value at the first time, then later is changing correctly after the first time but just after that.
The code is :

tagPaths = ['[default]app_tags/Componentes/ArranquePedidos/Alarma_Canal_Vacio','[default]app_tags/Componentes/ArranquePedidos/Alarma_Sector_Vacio']
tgCanal, tgSector = [qval.value for qval in system.tag.readBlocking(tagPaths)]

if tgCanal:
    #system.nav.centerWindow('User Management/mesajeAlarma')
    system.gui.getParentWindow(event).getComponentForPath('Root Container.lblCanalTag').text = tgCanal
    system.gui.getParentWindow(event).getComponentForPath('Root Container.lbSectorTag').text = tgSector

I was unable to replicate the behavior testing in a live session using this code for my internalFrameOpened event handler:

tagPaths = ['[default]app_tags/Componentes/ArranquePedidos/Alarma_Canal_Vacio','[default]app_tags/Componentes/ArranquePedidos/Alarma_Sector_Vacio']
tgCanal, tgSector = [qval.value for qval in system.tag.readBlocking(tagPaths)]
system.gui.getParentWindow(event).getComponentForPath('Root Container.lblCanalTag').text = tgCanal
system.gui.getParentWindow(event).getComponentForPath('Root Container.lbSectorTag').text = tgSector

In my test, I used the Alarma_Canal_Vacio tag to trigger the tag change event script. Both tags are string datatype. I did remove the if tgCanal: statement from the code because that doesn't seem to be needed, but when I went back and tried the script with the if statement, I still got the expected result. Do you see anything in my experiment that differs from your approach?

So, it worked for you ?