# Passing a table to runScript

**URL:** <https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484>\
**Category:** Ignition\
**Created:** [July 11, 2019, 4:18pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484 "2019-07-11T16:18:56Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [July 11, 2019, 4:18pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/1 "2019-07-11T16:18:56Z")

</div>

In Vision, I want to use a label component which shows the number of selected rows in a table.  
I can get the number of selected rows in a table with .getSelectedRowCount(), so I wrote:

> def getSelectedRowCount(table):  
> return table.getSelectedRowCount()

Now I'm trying to bind the label's text property to the following expression:

> runScript("utils.getSelectedRowCount", 0, {Root Container.MyTable})

but I get the error:

AttributeError: 'NoneType' object has no attribute 'getSelectedRowCount'

so I guess the table object is not passed correctly, which I suspected wouldn't work even before trying, but then how do I accomplish the task?

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [July 11, 2019, 4:25pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/2 "2019-07-11T16:25:55Z")

</div>

You can bind it to

```auto
len({Root Container.MyTable.data})

```

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [July 11, 2019, 4:32pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/3 "2019-07-11T16:32:01Z")

</div>

No, that doesn’t tell me the number of _selected_ rows in the table.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [July 11, 2019, 4:44pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/4 "2019-07-11T16:44:12Z")

</div>

Gah! Sorry I didn’t see the selected part.  
What I would do for this is create a custom property on the table called selected as an integer.  
Then in the propertyChange event of the table put the following code

```auto
if event.propertyName=='selectedRows':
	event.source.selected=event.source.getTable().getSelectedRowCount()

```

Then you just bind the label to that custom property.

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [July 11, 2019, 4:52pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/5 "2019-07-11T16:52:51Z")

</div>

Sorry but unless I’m missing something tables have no “selectedRows” property (the list of selected rows can only be obtained by calling .getSelectedRows() on the table object).

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [July 11, 2019, 4:53pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/6 "2019-07-11T16:53:58Z")

</div>

you missed the part of the code

```auto
.getTable()

```

😉

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [July 11, 2019, 4:55pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/7 "2019-07-11T16:55:50Z")

</div>

I mean that event.propertyName can never be “selectedRows”, since **vision** tables have no such property.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [July 11, 2019, 5:04pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/8 "2019-07-11T17:04:48Z")

</div>

Power Tables do, if you are using a regular table create the same custom property on the table, and then in the Mouse Released script put

```auto
event.source.selected = event.source.getTable().getSelectedRowCount()

```

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [July 11, 2019, 5:12pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/9 "2019-07-11T17:12:13Z")

</div>

Power tables in vision also do not have a “selectedRows” property.

I’d prefer to avoid the mouse released event approach since rows in my tables are selected/deselected by external events and controls, and not necessarily through clicking on the table itself.  
I could also update the selected row count inside those other components and events when they are fired, but it’s an approach that doesn’t scale.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 11, 2019, 5:16pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/10 "2019-07-11T17:16:10Z")

</div>

@MMaynard 's solution will indeed get you the result you need (though I see you have other requirements as well), without the overhead of having that script. As for why you can’t pass the table, Expressions do not allow for passing components. If you attempt to use the GUI (v8.0 and newer), you’ll actually receive an error dialog, informing you that you must supply a bindable property of the component.

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [July 11, 2019, 5:17pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/11 "2019-07-11T17:17:30Z")

</div>

Can I then pass the table’s full path as a string to the python code then get the object back when in python starting from the path string?

---

<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:** [July 11, 2019, 5:21pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/12 "2019-07-11T17:21:01Z")

</div>

> [@waldner](#):
>
> Power tables in vision also do not have a “selectedRows” property.

Actually, they do. It just isn't bindable. And doesn't generate propertyChange events. But it _ **is** _ available to scripts.

---

<div class="post-metadata">

**Author:** ![waldner](https://avatars.discourse-cdn.com/v4/letter/w/a5b964/32.png) [@waldner](https://forum.inductiveautomation.com/u/waldner)\
**Post date:** [July 11, 2019, 5:22pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/13 "2019-07-11T17:22:22Z")

</div>

> [@pturmel](#):
>
> > Power tables in vision also do not have a “selectedRows” property.
> 
> Actually, they do. It just isn’t bindable. And doesn’t generate propertyChange events. But it _ **is** _ available to scripts.

Well, then I suggest updating the docs, no mention of that here [Vision - Power Table - Ignition User Manual 8.0 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC80/Vision+-+Power+Table)

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 11, 2019, 5:24pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/14 "2019-07-11T17:24:32Z")

</div>

> [@waldner](#):
>
> Can I then pass the table’s full path as a string to the python code then get the object back when in python starting from the path string?

In _theory_, yes, but I'm not the one to ask in regard to how to accomplish such a feat.

---

<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:** [July 11, 2019, 5:35pm UTC](https://forum.inductiveautomation.com/t/passing-a-table-to-runscript/26484/15 "2019-07-11T17:35:46Z")

</div>

> [@waldner](#):
>
> Can I then pass the table’s full path as a string to the python code then get the object back when in python starting from the path string?

This is possible when runscript calls a custom method of a component, as you can use the `self` argument to indirectly access other components in that window. It is possible with the [objectScript()](https://www.automation-pros.com/simaids/doc/expression.objectscript.html) expression function (part of [Simulation Aids](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids)) without a custom method thanks to its `binding.target` local variable.
