# Request help with Expression Binding

**URL:** <https://forum.inductiveautomation.com/t/request-help-with-expression-binding/41138>\
**Category:** Ignition\
**Created:** [December 2, 2020, 4:01pm UTC](https://forum.inductiveautomation.com/t/request-help-with-expression-binding/41138 "2020-12-02T16:01:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![josephyliniemi](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@josephyliniemi](https://forum.inductiveautomation.com/u/josephyliniemi)\
**Post date:** [December 2, 2020, 4:01pm UTC](https://forum.inductiveautomation.com/t/request-help-with-expression-binding/41138/1 "2020-12-02T16:01:31Z")

</div>

I am trying to assign a value to a text field based off the results of an expression binding.

On the text field I am using the Binding type “Property” "Expression  
Within the expression I have:

`runScript("project.Defines.named")`

which calls the function

```auto
	import datetime
	window = system.gui.getWindow("Scan Barcode")
	snum = window.getRootContainer().getComponent("Text Field 2").text
	if snum != "" or snum != 0000000000:
		params = {"myValueX":snum}
		snum_result = system.db.runNamedQuery("query",params)
		return snum_result
	else:
		snum_result = "Invalid"
		return snum_result

```

when run the Text field displays

`Dataset [1R ⅹ 54C]`

How do I get a specific value, say row 0 column 36 or [0,36]? I have tried to adjust the expression to pass the row and column I am looking for and receive the error:

[AWT-EventQueue-2] ERROR com.inductiveautomation.factorypmi.designer.property.configurators.ExpressionConfigurator - Type mismatch in operation ‘Dataset Subscript’: expected ‘Dataset’, found ‘Object’

I want the named query to pull all data associated with value in Text Field 2 as that is the index key. Overall the 54 columns in that row will get distributed to different fields.  
I can set each field to run a sql query to get the data, but that runs 54 queries for one page.

The end result is I want the user to scan a barcode, the barcode gets parsed to a specific serial number that goes into Text Field 2. Some background magic occurs and the rest of the page is filled out with the data from the database.

Please advise on my mistakes or is there a better way?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 2, 2020, 4:47pm UTC](https://forum.inductiveautomation.com/t/request-help-with-expression-binding/41138/2 "2020-12-02T16:47:20Z")

</div>

I would use a propertyChange event on the text field

```auto
if event.propertyName == 'text':
    barcode = event.newValue
    if barcode != "" and barcode != 0:
        results = system.dataset.toPyDataSet(system.db.runNamedQuery("query",{"myValueX": barcode}))
        for row in results:
            data1 = row['data1']
            data2 = row['data2']
            data3 = row['data3']
        event.source.parent.getComponent('Data1').text = data1
        event.source.parent.getComponent('Data2').text = data2
        event.source.parent.getComponent('Data3').text = data3
    else:
        pass

```

If you have 54 columns per row, having them as individual fields is unwieldy. Just set the query data to a power table instead.

```auto
event.source.parent.getComponent('Power Table').data = results

```

More information may be needed for a better answer  
also, format your code by inclosing it with three back ticks before and after (above the tab key)

---

<div class="post-metadata">

**Author:** ![josephyliniemi](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@josephyliniemi](https://forum.inductiveautomation.com/u/josephyliniemi)\
**Post date:** [December 2, 2020, 4:56pm UTC](https://forum.inductiveautomation.com/t/request-help-with-expression-binding/41138/3 "2020-12-02T16:56:30Z")

</div>

Thank you for your reply, a power table would work except I am trying to fill in as (see Below)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/9/c95550c1d6e0d7e799f5b25de6212ad70151c77e.png)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 2, 2020, 6:28pm UTC](https://forum.inductiveautomation.com/t/request-help-with-expression-binding/41138/4 "2020-12-02T18:28:01Z")

</div>

Maybe write your dataset to a tag. I pretty sure you can use a tag binding to each element in the dataset.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/7/b72de96d1ad5a7fba0b197018b0bd484b37e522d.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 2, 2020, 6:45pm UTC](https://forum.inductiveautomation.com/t/request-help-with-expression-binding/41138/5 "2020-12-02T18:45:38Z")

</div>

Write it to a custom property, then use a lookup expression wherever you need to distribute it.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 2, 2020, 7:13pm UTC](https://forum.inductiveautomation.com/t/request-help-with-expression-binding/41138/6 "2020-12-02T19:13:49Z")

</div>

+1  
Cool, I forgot about the lookup expression (since I’ve never used it) 🙂
