How to Update Non Polling Expression Client Tag

I have a client tag that is a datset based on a SQL query. If I set the Polling Mode to Off, how can I get the tag to update its value when the data in the database table changes?

You would have to read the data in the database somehow to know when you needed to update the dataset, so I don’t think you can do this automatically without polling. You can trigger the update manually off a button press if that would work.

That would indeed work. By what mechanism would I do that? :slight_smile:

You can do this one of 2 ways: binding or scripting.

Binding

  1. Create a Client tag called ‘trigger’ with Data Type Boolean.
  2. Create a client tag of Data Type DataSet. Set its Expression Type to SQL Query, its Polling Mode Off and the query to SELECT * FROM table WHERE {[~]trigger}={[~]trigger}
  3. Create a button and set its actionPerformed script to value = system.tag.read('[Client]trigger').value system.tag.writeToTag('[Client]trigger', not value)When you click the button, the value of the tag ‘trigger’ will be toggled. This will change the text inside the SQL Query from SELECT * FROM Table WHERE 0=0 to SELECT * FROM Table WHERE 1=1This won’t change the result of the query but will force it to be updated.

Scripting

  1. Create a Client tag of Data Type DataSet.
  2. Create a button and set its actionPerformed script to data = system.db.runQuery("SELECT * FROM table") system.tag.write("[Client]Scripting tag", system.dataset.toDataSet(data))When you press the button the query will be run and the tag updated with the result.
1 Like