Accessing Component Properties from Extension Function

Hello-

I’m hoping to get some help with embedded dropdown list in PowerTable component. I have a table which I would like to select a variety from Column 0 dropdown (filled out by SQL query) and then Col1 is a lot code dependent on selection in Col0. I’m not sure how to link to value at selectedRow, Collumn0 like I would outside the extension function. Here’s what I have that is not working:

query = "SELECT DISTINCT ItemName FROM raw_materials_list WHERE ItmsGrpNam = 'Hops'"
hops = system.db.runQuery(query, 'Quality')
hops_options = []

for row in hops:
    hops_options.append((row[0],row[0]))

hop_var = self.data.getValueAt(self.selectedRow, 0)
query = "SELECT DISTINCT LotCode FROM raw_materials_list WHERE ItemName = '%s'" %hop_var
lots = system.db.runQuery(query, 'Quality')
lots_options = []

for row in lots:
	lots_options.append((row[0],row[0]))

if colName == 'Hop Variety':
    return {'options': hops_options}

elif colName == 'Lot Code':
    return {'options': lots_options}

The ‘Hop Variety’ dropdown works fine, but I’m not sure how to get the right value into hop_var so that ‘Lot Code’ query works (i’ve tried a few different things). What is the correct way to access the PowerTable’s component properties from its own extension function?

Hello,

From within your extension function you can access your other component properties in the following way:

col0Value = self.data.getValueAt(self.selectedRow,"col0")
1 Like

Thanks, Nick!

I changed hop_var to this (“Hop Variety” is col name), but still not working:

query = "SELECT DISTINCT ItemName FROM raw_materials_list WHERE ItmsGrpNam = 'Hops'"
hops = system.db.runQuery(query, 'Quality')
hops_options = []

for row in hops:
	hops_options.append((row[0],row[0]))

hop_var = self.data.getValueAt(self.selectedRow, "Hop Variety")
query = "SELECT DISTINCT LotCode FROM raw_materials_list WHERE ItemName = '%s'" %hop_var
lots = system.db.runQuery(query, 'Quality')
lots_options = []

for row in lots:
	lots_options.append((row[0],row[0]))

if colName == 'Hop Variety':
	return {'options': hops_options}

elif colName == 'Lot Code':
	return {'options': lots_options}

Sorry if I’m completely missing something stupid! This works fine when I just sub in hop_var = ‘Cascade’ so it is a problem with that particular getValueAt line

It works with:

hop_var = self.data.getValueAt(0,0)

so it must be an issue with “self.selectedRow”?

Are you sure you had the column name right? What if you accessed the column with a integer instead of a string?

Yes, this also does not work:

hop_var = self.data.getValueAt(self.selectedRow,0)

Its also not popping up with an error message, its just not showing the dropdown on either column. Do you know where I can find the error? That might make it easier to figure out.

What I have posted above is the entire script in the configureEditor extension function. Should I need to import something into this script to make the selectedRow property accessible? It would be weird though if I can get to self.data and not self.selectedRow though, yes?

Found this in output console:

ERROR [AdvancedTable-AWT-EventQueue-2] Error invoking extension method.
 Traceback (most recent call last):
  File "<extension-method configureEditor>", line 33, in configureEditor
    at com.inductiveautomation.ignition.common.BasicDataset.getValueAt(BasicDataset.java:114)
    at sun.reflect.GeneratedMethodAccessor237.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: -1

You seem to think this extension function is called as you navigate in the table. It is called once for each column during setup of the table. If you search the forum for “configureEditor”, you’ll see a number of discussions and the custom editor you would need.

Perhaps you should use the “onCellEdited” extension function instead of the configureEditor extension function.

Ah, yes! This is the “completely stupid thing I am missing”- this issue makes a lot more sense now :). I’ll look into the custom editor, I wasn’t quite sure what to search for before. Thanks for the clarification.

Hi Nick,

Does the SDK reveal which libraries a particular extension function or event handler is using?

I’m modifying the visibility of certain y-axes on an EasyChart using the configureChart extension function. Originally, I thought that changing the state of a value in the configureChart function would invoke that function, but it appears it’s only called for a limited set of events.

My plan is to move the script from the configureChart extension function to a checkbox event handler function. Will I need to figure out which underlying libraries of the configureChart function is using so as to import them into the event handler function?