Client DataSet SQL Refresh

Is there a way to update a client DataSet that is bound to a SQL query on demand?

I have a client dataset that pulls data from a database and polling is set to off. However if a record is added to the table by runtime I’d like to be able to force a refresh of that data to the dataset. Is there a way to do that without setting up polling?

How or where is the record being added to the Table by runtime? Maybe some how reorganize your Client Dataset/ Graphic Objects so can call system.db.refresh() on a component. There’s polling and system.db.refresh(), not sure of ways of updating? I don’t think you can call system.db.refresh on a Client Tag?

I’m adding the row via a button on the gui so I know when it is getting updated. I tried the system.db.refresh but it didn’t like the client tag.

This is configuration data for a backend part of the system, so it won’t get updated often, but when it does get updated it would be nice to be able to refresh the table with the new data.

There’s no supported way to refresh a Client Tag. Put the following in a shared or project script for an unsupported method:

from com.inductiveautomation.factorypmi.application import FPMIApp
from com.inductiveautomation.ignition.common.sqltags.parser import TagPathParser

# Support refresh of normally non-refreshing client expression tags and client SQL query tags
def refresh(tagname):
	tp = TagPathParser.parse(tagname)
	ctx = FPMIApp.getInstance().adapterContext
	node = ctx.tagManager.getTag(tp)
	node.startBinding(ctx, node.path)

EDIT: retrieve the adapterContext instead of the clientContext for all cases. Pretty sure this will work everywhere, in all recent Ignition versions.

2 Likes

I stuck your code in a shared script and I got this error:

AttributeError: ‘com.inductiveautomation.factorypmi.application.FPM’ object has no attribute ‘clientContext’

BTW I’m using 7.9.9 if that matters.

See the edit above, using adapterContext in place of clientContext.

Works like a charm.

So… related to this. Where would I find the latest API? The only one I can find is 7.8.4.

This is the one I spend the most time with:

http://files.inductiveautomation.com/sdk/javadoc/ignition79/795/index.html

1 Like

Can’t you work with a tag as trigger? I often use this to refresh queries in the interface, but when I have no direct access to the table (f.e. adding a record from a popup).

Typically, I make a boolean tag, and then define the query like this:

SELECT MyColumn
FROM MyTable
WHERE Condition = 'whatever' AND
      {path/to/triggerBit} = {path/to/triggerBit}

Whenever the bit is toggled, the query is refreshed as one of the bound tags is changed, but the results are still the same (0=0 and 1=1 are always true).

I don’t know if this works on client tags though, I don’t use that very often. My queries tend to either be global (always return the same result for all clients), or UI-dependent.

And just to be a party pooper, FPMIApp.getInstance() is deprecated and may be removed in 8+. It’s still there right now, but it’s fair game for removal at any time.

Us module developers are kinda used to this, in general. Which is why I clearly noted this was unsupported. It’d be nice if there was an official way to refresh a client tag binding before y’all break this work-around. It’d be super-awesome if the official refresh operation worked on both bound client tags and your future gateway-side scan-class-less expression/query tags. (-:

4 Likes

Did this ever happen? I’m looking for the same thing right now. Have one tag using a Named Query that I would like to be able to have poll on-demand since I know when it needs refreshed. I don’t need a 5 second refresh if nothing has changed, and a 5 minute refresh is useless, as I need to see the new result set NOW.

2 Likes