# Is it possible to change a table's data via a script?

**URL:** <https://forum.inductiveautomation.com/t/is-it-possible-to-change-a-tables-data-via-a-script/73126>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 2, 2023, 1:46am UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-change-a-tables-data-via-a-script/73126 "2023-05-02T01:46:10Z")\
**Posts on this page:** 6\
**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:** [May 2, 2023, 1:46am UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-change-a-tables-data-via-a-script/73126/1 "2023-05-02T01:46:10Z")

</div>

I have a view with two buttons, and a table. I'd like to change the named query the table is bound to depending on which button is clicked. I've been searching the docs and forums but have not been able to find a solution.

If this is possible, how would I go about it?

Thanks,  
Mike

---

<div class="post-metadata">

**Author:** ![franklepkowski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/franklepkowski/32/4808_2.png) [@franklepkowski](https://forum.inductiveautomation.com/u/franklepkowski)\
**Post date:** [May 2, 2023, 1:53am UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-change-a-tables-data-via-a-script/73126/2 "2023-05-02T01:53:47Z")

</div>

Hello,

You could create two custom properties on your view and bind them to each of your two named queries. Then in your button event script set the table data to the proper custom property.

Frank

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [May 2, 2023, 1:57am UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-change-a-tables-data-via-a-script/73126/3 "2023-05-02T01:57:23Z")

</div>

I do something similar based on a drop down.

I’m not at my work computer so can’t give examples but as a high level…

You can create a custom property on the table, or a session property depending which road you want to take and bind it to the table data.

On the button action performed, create a script to call the named query and write the result to the custom property.

Depending on what your query is, you can possibly use the same named query and just pass different parameters. It’s amazing how many uses you can make out of the same query by passing parameters.

---

<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:** [May 2, 2023, 5:00pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-change-a-tables-data-via-a-script/73126/4 "2023-05-02T17:00:15Z")

</div>

Thanks Frank, that works well!

---

<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:** [May 2, 2023, 5:03pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-change-a-tables-data-via-a-script/73126/5 "2023-05-02T17:03:38Z")

</div>

To write the resulting data set to the table, would that be setting the table custom property to an array, then looping through the data to populate the array?

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [May 2, 2023, 5:41pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-change-a-tables-data-via-a-script/73126/6 "2023-05-02T17:41:46Z")

</div>

I do it different to Frank but same result.

On the button I have the following example code. I've cut out the custom property part as you can write the result straight to the table data.

```auto
# Create a Python dictionary of parameters to pass.
params = {"param1":"my string", "param2":10}
  
# Query Path.
path = "Query/MyQuery"

# Run the Query
ds = system.db.runNamedQuery(path, params)

# Send results to table
Table.props.data = ds

```

Haven't tried this but you can do it a similar way using Franks Method.  
On the button..

```auto
ds = "path to custom property that has your named query result"
Table.props.data = ds

```
