System.dataset not working in Client Tag Change Script

If I use the following code on a button, it works fine. I can call incRow further down in the script.
But if i use it in a Tag Change Script, I get NameError: global name ‘system’ is not defined

def incRow():
newData = system.dataset.setValue(, row,0,1) # set value inf first column = newData
value = row + 1 # then increment pointer to move down the list
table.selectedRow = value # set the selectedRow to the new value

It looks like your trying to look at a table on the screen from a tag script. I don’t believe that can be done. Even with it being a client tag it isn’t directly attached to the screen so when the tag changes it doesn’t know where to look. Is it trying to change values in the client tag itself or somewhere else?

“table” is a local variable defined further up in the code
table = mywindow.getRootContainer().getComponent(‘Tbl_Inst’)
This is in a Client Event Script. Tag Change.
Also if i use the four lines of script elsewhere in the script, it works fine, just not when contained in the incRow function. But since that gets used several times throughout the code i thought it would be more efficient (or at least cleaner looking) to define a function then call it.

Event scripts use an ancient jython compatibility mode–a leftover from v7.6.x IIRC. Anyways, one of the side effects of that compatibility mode is that system, shared, project, etc are only automatically present at the top level of the script, not in any nested function or class. You can import them inside the function definition, or, for a more robust solution, delegate from the event to a project script, passing the arguments needed. I like one-liners:


It’s also best, if you have repeating code, to put it in a script module, not redefine at every script execution. The only functions that need defining in-line are those that need runtime variables in their closures.

1 Like