Request help with Expression Binding

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:


which calls the function

	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
		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 - 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?

I would use a propertyChange event on the text field

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

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

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)

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

Maybe write your dataset to a tag. I pretty sure you can use a tag binding to each element in the dataset.

1 Like

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

1 Like

Cool, I forgot about the lookup expression (since I’ve never used it) :slight_smile: