Reading a DB tag when opening a window

I am reading a DB tag using system.tag.getTagValue in a window’s internalFrameActivated event. The tag is a string and is blank, but the read returns a value of -1.

Is there any way to reliably read whether a string DB tag is blank or not?



It appears that that function currently returns -1 for “tag not found”. It will be changed to throw an error like it should. At any rate, an incorrect tag path appears to be your problem.


Hi Colby,

I took the code from the window’s internalFrameActivated event and put it on a button, where it worked perfectly.

The window (call it ‘window A’) was set to open on startup, so I created another window (call it ‘window B’) to open on startup which contained a button to launch window A. The first time I switched from window B to A the code still didn’t run correctly. However, when I switched back to window B and then back to window A a second time, it worked correctly and worked every time thereafter.

Any thoughts? I’ve attached the 2 windows in case they help you spot anything (with an extra extension as the forum software says that the extension ‘vwin’ is not allowed). You will have to create a string SQLTag called ‘postIt’ to run the windows.
Test.vwin.txt (14 KB)

This example has brought out a slight timing issue that we’ll have to fix. When you call system.tag.getTagValue, it checks to see if you are subscribed to the tag. If you are, it simply gives you the value from the subscription system, assuming that by being subscribed, the tag is up-to-date. If you’re not subscribed, then it will synchronously read the tag’s value from the Gateway.

What is happening in your example is this:

  1. Window opens
  2. Bindings start up, subscribe to tag “postIt”
  3. Window’s internalFrameActivated event fires. Sees that postIt is subscribed, pulls value from subscription system, which is -1, because…
  4. 1st subscription poll returns 250ms later, which has the real value for postIt.

We’ll fix this for the next release, but in the meantime you can work around it by changing your internalFrameActivated script to this:

def startup(event=event): import system myText="" myText = system.tag.getTagValue('[]postIt') postIt = system.gui.getParentWindow(event).getComponentForPath('Root Container.Post_It') label = system.gui.getParentWindow(event).getComponentForPath('Root Container.Label') label2 = system.gui.getParentWindow(event).getComponentForPath('Root Container.Label 2') if myText=="": postIt.visible=0 label.text = "Text NOT available" else: postIt.visible=1 label.text = "Text available" label2.text = "*%s*" % myText system.util.invokeLater(startup, 500)

Thanks Carl, the workaround works well :slight_smile: