Ignition tag change script help

Hello, I have made an interface with several tables that are fed by a named query. Anytime the OPC tag changes values, a message is sent to reload the table. I know the message handler is correct.

On the view for the table, I placed a custom property with a tag change script. When the tag changes, it is supposed to automatically refresh the table. the problem is it is always one behind. I loads the last data point, not the one it just switched to. This may be due to my transaction group falling sending after my tag change script runs. here is the script.

If you look at the image the end has already been sent, but has not loaded.

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
if currentValue is not None:
system.perspective.sendMessage(
messageType="refresh",
scope="view"
)

Looks like you might have messed up the preformatted text formatting, see Wiki - how to post code on this forum.

You need to guarantee that the transaction group runs and completes before you trigger the table refresh. You are ending up with a race condition between your transaction group and your query against the DB for the latest records.

The only way to guarantee ordering is to script your transaction in a Gateway Tag Change event, and at the end of the transaction script, use system.util.sendMessage to send a message aimed at the project where this view resides.

From there, in the Session Message Handler, use system.perspective.sendMessage with a session scope to trigger the table refresh. Adjust your table message handler to listen at the session level.

Also I don’t think currentValue is ever None. previousValue in the other hand can be. Perhaps you are meaning to check the value of it instead? Eg currentValue.value

(Not that this would cause the issue you're seeing)