# How to update a query tag?

**URL:** <https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [March 31, 2023, 8:15pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924 "2023-03-31T20:15:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 31, 2023, 8:15pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/1 "2023-03-31T20:15:01Z")

</div>

Hello all,

View 1 contains a table bound to a tag with a named query. User selects a record, clicks edit, opens a popup to view/edit the details. User selects the new value to replace the old value, clicks confirm changes, and another tag with a named update query runs.

How do I get the View 1 table data refreshed? It still displays the old values, even with a browser refresh.

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 31, 2023, 8:25pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/2 "2023-03-31T20:25:33Z")

</div>

> [@mdemaris](#):
>
> and another tag with a named update query runs.

Why would you do that with a tag? Updates are generally done in an action script. The table probably should have the named query directly bound, and then your action script can request a refresh after the update operation completes.

Don't use gateway tags for UI elements, unless you expect the value to be broadcast to all possible clients.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 31, 2023, 8:32pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/3 "2023-03-31T20:32:31Z")

</div>

My mistake: View 1's tag is direct bound, using a query statement in the tag itself.

Here is the script on the "Confirm Change" button:

```auto
def runAction(self, event):
	# update User table deptID where User ID = XXX to
	# table props selection data[0][''] 
	userID = self.view.params.v_UserID
	deptID = self.parent.parent.getChild("TableContainer").getChild("Table").props.selection.data[0]['ID']
	system.perspective.print(deptID)
	params1 = {"deptid":deptID, "userid":userID}
	namedQuery = "UpdateUserDept"
	system.db.runNamedQuery(namedQuery, params1)

```

What function would I use to send the update to the DB and then request a refresh?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 31, 2023, 8:35pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/4 "2023-03-31T20:35:55Z")

</div>

Ok, you're really close.

Add one more line like so:

```auto
	self.getSibling('MyTable').refreshBinding('props.data')

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 31, 2023, 8:38pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/5 "2023-03-31T20:38:16Z")

</div>

Actually, not a sibling, based on your deptID. More like so:

```auto
def runAction(self, event):
	# update User table deptID where User ID = XXX to
	# table props selection data[0][''] 
	userID = self.view.params.v_UserID
	Table = self.parent.getSibling("TableContainer").getChild("Table")
	deptID = Table.props.selection.data[0]['ID']
	system.perspective.print(deptID)
	params1 = {"deptid":deptID, "userid":userID}
	namedQuery = "UpdateUserDept"
	system.db.runNamedQuery(namedQuery, params1)
	Table.refreshBinding("props.data")

```

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 31, 2023, 8:40pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/6 "2023-03-31T20:40:32Z")

</div>

> [@pturmel](#):
>
> Don't use gateway tags for UI elements

What's another way to not use a tag for an update query?  
something like:

```auto
system.runCode "UPDATE statement..."

```

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 31, 2023, 8:43pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/7 "2023-03-31T20:43:08Z")

</div>

What if I put the refresh statement in the script calling the popup view? Would it run all the code before the popup loads or would it wait for the popup to close then resume running the script?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 31, 2023, 8:49pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/8 "2023-03-31T20:49:01Z")

</div>

> [@mdemaris](#):
>
> What's another way to not use a tag for an update query?

You aren't using a tag for your update query. And you said your table is directly bound to the select named query. So, no tag involved. You're good.

Wait. You said your tag is direct bound to the named query. You must be confused, because that isn't supported.

Eww. Unless it is a client tag. Those cannot be directed to refresh. Don't bind queries to client tags. Just bind the table's data to the named query.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 31, 2023, 8:54pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/9 "2023-03-31T20:54:28Z")

</div>

Lol.

The primary table, View 1, is bound to a query tag.

the popup view allows the user to change some value, use a TAG connected to a Named Query, to update the table data.

Close the popup, the changes are not realized on View 1.

Refresh the table on the server and I can see the update was made.

Also... I added a refresh binding script after the call to open the popup but that didn't refresh the View 1 data.  
Popup action: from View 1

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/7/4781cdf573c3fd0bdcfce6bba8e3627724426990.png)

Script action:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/f/4f63ab37efc29416847d4c67632c01fb4ff7c44b.png)

didn't work.

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 31, 2023, 8:55pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/10 "2023-03-31T20:55:33Z")

</div>

From the popup confirm change button action:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/6/663ef7392e0b74dbe0134646d001cd07baa871a6.png)

---

<div class="post-metadata">

**Author:** ![mdemaris](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mdemaris/32/54639_2.png) [@mdemaris](https://forum.inductiveautomation.com/u/mdemaris)\
**Post date:** [March 31, 2023, 9:02pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/11 "2023-03-31T21:02:13Z")

</div>

> [@pturmel](#):
>
> Unless it is a client tag

When I create tags in the designer, these are considered client tags?

> [@pturmel](#):
>
> Just bind the table's data to the named query.

Done. So a change script or refresh is still needed looks like.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 31, 2023, 9:09pm UTC](https://forum.inductiveautomation.com/t/how-to-update-a-query-tag/71924/12 "2023-03-31T21:09:30Z")

</div>

> [@mdemaris](#):
>
> considered client tags?

No, only tags created in the Vision Client Tag provider. Such tags are per-client at runtime, and are commonly used to hold client-wide (but not system-wide) state.

System-wide state is held in gateway tags (the default and other real-time providers). UI data should not go through gateway tags unless it is so commonly displayed on all/most clients that broadcasting efficiently via tag makes sense.

> [@mdemaris](#):
>
> refresh is still needed looks like.

Yes, unless the binding is set to polling. But that burns CPU on gateway and DB to no purpose in most cases. Use `.refreshBinding()` when you know the data has changed (because you just changed it, typically).
