# Power Table for loop for each row

**URL:** <https://forum.inductiveautomation.com/t/power-table-for-loop-for-each-row/41972>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [January 5, 2021, 2:06pm UTC](https://forum.inductiveautomation.com/t/power-table-for-loop-for-each-row/41972 "2021-01-05T14:06:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgonya](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgonya/32/9304_2.png) [@jgonya](https://forum.inductiveautomation.com/u/jgonya)\
**Post date:** [January 5, 2021, 2:06pm UTC](https://forum.inductiveautomation.com/t/power-table-for-loop-for-each-row/41972/1 "2021-01-05T14:06:16Z")

</div>

I trying to run an update named query for each row on a power table. I set up the power table that can “pick up and drag” each row. Each row is number in the database. The update is to change the number.

table = event.source.parent.getComponent(‘Goals\_Year’)  
rowCount = event.source.parent.getComponent(‘Goals\_Year’).data.getRowCount()

for row in range(rowCount):  
selectId = event.source.parent.getComponent(‘power table’).data[row, “Id”]  
newValue = row

```
namedQuery = 'Update'
params = {
	'newValue':newValue, 
	'Id':selectId
	}
system.db.runNamedQuery(namedQuery, params)

```

system.db.refresh(table, ‘data’)

I believe the error is on the for loop line. Right now the script is in a button on the window.

---

<div class="post-metadata">

**Author:** ![jgonya](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgonya/32/9304_2.png) [@jgonya](https://forum.inductiveautomation.com/u/jgonya)\
**Post date:** [January 5, 2021, 2:34pm UTC](https://forum.inductiveautomation.com/t/power-table-for-loop-for-each-row/41972/2 "2021-01-05T14:34:20Z")

</div>

looking into this more this line isn’t working.  
selectId = event.source.parent.getComponent(‘power table’).data[row, “Id”]

I use something like this in an expression binding witch works.

{Root Container.power table.data} [{Root Container.power table.selectedRow} , “Id”]

So I have to pull data out of the row in scriping not expression. Any help would be helpful.

---

<div class="post-metadata">

**Author:** ![jgonya](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgonya/32/9304_2.png) [@jgonya](https://forum.inductiveautomation.com/u/jgonya)\
**Post date:** [January 5, 2021, 2:42pm UTC](https://forum.inductiveautomation.com/t/power-table-for-loop-for-each-row/41972/3 "2021-01-05T14:42:56Z")

</div>

Got it.

table = event.source.parent.getComponent(‘power table’)  
rowCount = event.source.parent.getComponent(‘power table’).data.getRowCount()

rowselect = 0

for row in range(rowCount):  
selectId = event.source.parent.getComponent(‘power table’).data.getValueAt(row, “Id”)  
newValue = rowselect + 1

```
namedQuery = 'Update'
params = {
	'newValue':newValue, 
	'Id':selectId
	}
system.db.runNamedQuery(namedQuery, params)

rowselect = newValue

```

system.db.refresh(table, ‘data’)
