# Scripting & Binding

**URL:** <https://forum.inductiveautomation.com/t/scripting-binding/2264>\
**Category:** Ignition\
**Created:** [October 15, 2010, 5:05pm UTC](https://forum.inductiveautomation.com/t/scripting-binding/2264 "2010-10-15T17:05:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmoniz](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jmoniz](https://forum.inductiveautomation.com/u/jmoniz)\
**Post date:** [October 15, 2010, 5:05pm UTC](https://forum.inductiveautomation.com/t/scripting-binding/2264/1 "2010-10-15T17:05:40Z")

</div>

Hello All,

I have a table (lets call it “table 1”)on a screen displaying OEE and Throughput information. On the same screen i have a pie chart showing my downtime to operating time ratio (Lets call it “Chart 2”)

Question:

Is it possible to set the data binded to “Chart1” to the row selected by the user in “table 1”

Right now I have “Chart 1” binded to a SQL statement

SELECT Operating\_Time, Downtime\_Total FROM p4oee order by p4oee\_ndx desc limit 1

And would like to give the users to view “Chart 1” data based on row selection from “table 1”

“Table 1” SQL Binding:

SELECT  
Actual\_Footage,  
OEE \* 100,  
Planned\_Time / 60,  
Operating\_Time / 60,  
Downtime\_Total / 60,  
t\_stamp  
FROM p4oee  
ORDER BY t\_stamp DESC

Thanks  
JP

---

<div class="post-metadata">

**Author:** ![jmoniz](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jmoniz](https://forum.inductiveautomation.com/u/jmoniz)\
**Post date:** [October 15, 2010, 5:44pm UTC](https://forum.inductiveautomation.com/t/scripting-binding/2264/2 "2010-10-15T17:44:50Z")

</div>

Answered my own Question

WhereClause =

if({Root Container.Pilger 4.Table 1.selectedRow} = -1,

```
"n/a", // this is the fail case

{Root Container.Pilger 4.Table 1.data}[{Root Container.Pilger 4.Table 1.selectedRow}, "p4oee_ndx"])

```

Chart1 SQL Binding =

SELECT Operating\_Time, Downtime\_Total FROM p4oee Where p4oee\_ndx ={Root Container.Pilger 4.WhereClause}

---

<div class="post-metadata">

**Author:** ![guypb](https://avatars.discourse-cdn.com/v4/letter/g/c6cbf5/32.png) [@guypb](https://forum.inductiveautomation.com/u/guypb)\
**Post date:** [November 8, 2010, 1:02pm UTC](https://forum.inductiveautomation.com/t/scripting-binding/2264/3 "2010-11-08T13:02:42Z")

</div>

I’ve tried finding the answer, but how do I capture multiple selected values/strings in a table?

The standard expression works great for a single selection, but I wish to return the results from a multiple interval selection into a SQL query.

The expression is:  
if({Root Container.tblFeatureID.selectedRow} = -1,  
“n/a”, // this is the fail case  
{Root Container.tblFeatureID.data}[{Root Container.tblFeatureID.selectedRow}, “FeatureID”])

and the SQL query is:

select Operid, Sampleid, Featureid, Nominal, Actual, Deviation, Lowertol, Uppertol, Pass\_Fail, Notes  
from tblReporter  
where FeatureID = ‘{Root Container.tblFeatureID.SelectedValue}’  
order by SampleID

---

<div class="post-metadata">

**Author:** ![dep05d](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@dep05d](https://forum.inductiveautomation.com/u/dep05d)\
**Post date:** [November 11, 2010, 3:40pm UTC](https://forum.inductiveautomation.com/t/scripting-binding/2264/4 "2010-11-11T15:40:01Z")

</div>

Rather than using an expression, with scripting you could use the getSelectedRows() method on the table to iterate through each row and build a string to use in your SQL query:

for row in event.source.parent.getComponent(‘Table 1’).getSelectedRows():  
#use event.source.parent.getComponent(‘Table 1’).data.getValueAt(row,“yourColumn”)

You could put a dynamic string property on the table and when the selected row(s) change, fire off a script to rebuild the string, and use that string in your SQL query.

Dan
