# How to populate Component Input Fields From a Tables Row Selection Based on ID

**URL:** <https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531>\
**Category:** Ignition\
**Created:** [August 9, 2020, 5:27pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531 "2020-08-09T17:27:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 9, 2020, 5:27pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/1 "2020-08-09T17:27:27Z")

</div>

How to populate Component Input Fields From a Tables Row Selection Based on ID?

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 9, 2020, 6:41pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/2 "2020-08-09T18:41:46Z")

</div>

I am working on the insert statement to a database by a button click but I am not sure how to accomplish my original question. It will be a update statement to a database by selected row.

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 9, 2020, 9:57pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/3 "2020-08-09T21:57:26Z")

</div>

I have my insert statement working, I am now working on the row selection update statement. This is what I have so far… not much

```auto

```

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 9, 2020, 10:20pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/4 "2020-08-09T22:20:49Z")

</div>

Maybe some help for you…

```auto
table = event.source.parent.getComponent(“Table”).data
selRow = table.getSelectedRow()
selCol = table.getSelectedColumn()

data = data.getValueAt(selRow, selCol)

```

[https://docs.inductiveautomation.com/display/DOC79/Read+a+Cell+from+a+Table](https://docs.inductiveautomation.com/display/DOC79/Read+a+Cell+from+a+Table)

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 9, 2020, 10:37pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/5 "2020-08-09T22:37:20Z")

</div>

Once I get the row selection right. I need to populate my entry components. Then when I update the desired components values I am updating from a button if that helps. Here is a pic

 ![pic](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/d/ad94efaa58514e06b27b303b2902ecb55257139f.png)

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 9, 2020, 10:58pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/6 "2020-08-09T22:58:33Z")

</div>

What I usually do is create custom properties and bind using an expression like this:

```auto
try({Root Container.Table.data}[{Root Container.Table.selectedRow}, “Status”], -1)

```

“Status” is the column and “-1” is the failover value (value it will be if no value returned)

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 12, 2020, 11:54am UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/7 "2020-08-12T11:54:15Z")

</div>

> [@jlandwerlen](#):
>
> try({Root Container.Table.data}[{Root Container.Table.selectedRow}, “Status”], -1)

I get a error when I try this: Scan Error. illegal character"\>(Line 1, Char 69)

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 12, 2020, 12:01pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/8 "2020-08-12T12:01:58Z")

</div>

> [@jlandwerlen](#):
>
> try({Root Container.Table.data}[{Root Container.Table.selectedRow}, “Status”], -1)

It's the quotes, something in the copy/paste. Delete the quotes and retype, with single or double.

Example, “Status” vs "Status" or 'Status'

Edit, looks like the forum "cleaned" up the example. If you copied into notepad you will see the difference in the quotes. Nonetheless, it's the quotes.

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 12, 2020, 12:14pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/9 "2020-08-12T12:14:37Z")

</div>

Yeah that worked to get the ID Column

---

<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:** [August 12, 2020, 12:14pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/10 "2020-08-12T12:14:40Z")

</div>

If you don’t use formatting marks when pasting code or other plain text into the forum, the forum treats it as paragraphs of prose, and pretties it up. Among other things, it substitutes paired curly quotes for straight quote characters, for that professional “article” appearance.

Lesson: don’t copy code from this forum that isn’t in a code format block.

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 12, 2020, 12:20pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/11 "2020-08-12T12:20:42Z")

</div>

So in order to populate each component entry I assume I do the same thing for each entry location.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [August 12, 2020, 12:32pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/12 "2020-08-12T12:32:18Z")

</div>

Yes, obviously referencing the specific column for each

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 12, 2020, 12:55pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/13 "2020-08-12T12:55:19Z")

</div>

I got each entry bound to a custom property and it populates each one by the selected row, I am working on my update statement now. When I run this I get a error for my where clause. I have the select statement similar to my insert statement. I am I going about it wrong?

```auto
query = "Update Equipment Set where EquipmentID = 'event.source.parent.getComponent('Table').EquipmentID'(DateTm,Equip,AccountCode,Descr,TypeID,DepartmentID,MaintLocationID,PlantLocID,EquipTypeID,DelFlg,Gauss,Refractory) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"
		args = [event.source.parent.getComponent('DateTm').date,event.source.parent.getComponent('Equip').text,event.source.parent.getComponent('Account Code').text,event.source.parent.getComponent('Descr').text,event.source.parent.getComponent('TypeID').selectedValue,event.source.parent.getComponent('DepartmentID').selectedValue,event.source.parent.getComponent('MaintLocationID').selectedValue,event.source.parent.getComponent('PlantLocID').selectedValue,event.source.parent.getComponent('EquipTypeID').selectedValue,event.source.parent.getComponent('DelFlg').selected,event.source.parent.getComponent('Gauss').selected,event.source.parent.getComponent('Refractory').selected]
		system.db.runPrepUpdate(query, args)

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 12, 2020, 1:25pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/14 "2020-08-12T13:25:11Z")

</div>

Perhaps this was a copy paste error, but I am fairly certain that the query as you have it will not run in your data base.

You need to replace the reference to the equipment ID with a question mark and also include that in your args list.

I don’t know what database you are using, but if your column name is ‘Equipment Set’ with a space then you should use square brackets, quotes, or some other delineation to represent to the Engine that it is a column name and not intended to be a Keyword. This is why it is generally recommended not to use spaces, key words, or Function names in/as column names.

Something like this:

```auto
query = "Update [Equipment Set] where EquipmentID = ? (DateTm,Equip,AccountCode,Descr,TypeID,DepartmentID,MaintLocationID,PlantLocID,EquipTypeID,DelFlg,Gauss,Refractory) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"
		args = [event.source.parent.getComponent('Table').EquipmentID,event.source.parent.getComponent('DateTm').date,event.source.parent.getComponent('Equip').text,event.source.parent.getComponent('Account Code').text,event.source.parent.getComponent('Descr').text,event.source.parent.getComponent('TypeID').selectedValue,event.source.parent.getComponent('DepartmentID').selectedValue,event.source.parent.getComponent('MaintLocationID').selectedValue,event.source.parent.getComponent('PlantLocID').selectedValue,event.source.parent.getComponent('EquipTypeID').selectedValue,event.source.parent.getComponent('DelFlg').selected,event.source.parent.getComponent('Gauss').selected,event.source.parent.getComponent('Refractory').selected]
		system.db.runPrepUpdate(query, args)

```

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 12, 2020, 1:30pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/15 "2020-08-12T13:30:22Z")

</div>

The Table name is Equipment not Equipment Set. I am using Sql Server 2012

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 12, 2020, 1:34pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/16 "2020-08-12T13:34:39Z")

</div>

Set is part of the Update statement I am trying to accomplish

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 12, 2020, 1:55pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/17 "2020-08-12T13:55:03Z")

</div>

I modified my update query to this. When I press the button everything seems to work, I don’t get any errors but it doesn’t actually update the selected row in the database table.

```auto
query = "UPDATE Equipment SET DateTm = ?, Equip = ?, AccountCode = ?, Descr = ?, TypeID = ?, DepartmentID = ?, MaintLocationID = ?, PlantLocID = ?, EquipTypeID = ?, DelFlg = ?, Gauss = ?, Refractory = ? WHERE EquipmentID = ?"
args = [event.source.parent.getComponent('Table').EquipmentID,event.source.parent.getComponent('DateTm').date,event.source.parent.getComponent('Equip').text,event.source.parent.getComponent('Account Code').text,event.source.parent.getComponent('Descr').text,event.source.parent.getComponent('TypeID').selectedValue,event.source.parent.getComponent('DepartmentID').selectedValue,event.source.parent.getComponent('MaintLocationID').selectedValue,event.source.parent.getComponent('PlantLocID').selectedValue,event.source.parent.getComponent('EquipTypeID').selectedValue,event.source.parent.getComponent('DelFlg').selected,event.source.parent.getComponent('Gauss').selected,event.source.parent.getComponent('Refractory').selected]
		system.db.runPrepUpdate(query, args)

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 12, 2020, 2:00pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/18 "2020-08-12T14:00:30Z")

</div>

You need to put the EquipmentID at the end of list, because now it is the last parameter not the first. Most likely it didn’t find an EquipmentID so no rows were modified.

Also, note that you can verify if any rows were modified by taking the return value of the runPrepUpdate funciton. It returns an integer equal to the number of rows modified by the query.

I think this is the code you’re looking for:

```auto
query = "Update Equipment SET DateTm = ?, AccountCode= ?, Descr = ?, TypeID =?, DepartmentID =?, MaintLocationID = ?, PlatnLocID=?, EquipTypeID=?,DelFlg=?,Gauss=?, Refractory=? Where EquipmentID = ?"
args = [event.source.parent.getComponent('DateTm').date,event.source.parent.getComponent('Equip').text,event.source.parent.getComponent('Account Code').text,event.source.parent.getComponent('Descr').text,event.source.parent.getComponent('TypeID').selectedValue,event.source.parent.getComponent('DepartmentID').selectedValue,event.source.parent.getComponent('MaintLocationID').selectedValue,event.source.parent.getComponent('PlantLocID').selectedValue,event.source.parent.getComponent('EquipTypeID').selectedValue,event.source.parent.getComponent('DelFlg').selected,event.source.parent.getComponent('Gauss').selected,event.source.parent.getComponent('Refractory').selected,event.source.parent.getComponent('Table').EquipmentID]
res = system.db.runPrepUpdate(query, args)
print 'Updated ' + str(res) + ' rows'
```

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [August 12, 2020, 2:23pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/19 "2020-08-12T14:23:55Z")

</div>

I tried your code but it acts the same as mine above. It acts like it is ok, No errors but doesn’t actually update the database table.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 12, 2020, 2:25pm UTC](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531/20 "2020-08-12T14:25:43Z")

</div>

Did it return a value other than zero?

[Next page](https://forum.inductiveautomation.com/t/how-to-populate-component-input-fields-from-a-tables-row-selection-based-on-id/37531.md?page=2)
