Pull cell data from perspective table

Hello, I have a JSON formatted table that I'm trying to read a value from a specific column, on the selected row and write that value back to a tag that is failing.

Current event script:

def runAction(self, event):
	
	val=self.props.data[selectedRow]['MPAID'].value
	#self.props.selection.selectedRow
	tag="[default]Perspective/MPAID"
	system.tag.writeBlocking(tag,val)

The first column in this table is a column titled "MPAID" that I'm trying to reference in a seperate embedded view, when I click on this table however I get the following error back:

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "function:runAction", line 2, in runAction
NameError: global name 'selectedRow' is not defined
caused by org.python.core.PyException
Traceback (most recent call last):
File "function:runAction", line 2, in runAction
NameError: global name 'selectedRow' is not defined

I'm assuming that "selectedRow" is not the right usage here, but I'm not sure what else to use here, any advice? Thanks in advance!

Try replacing the above line with

val=self.props.data[self.props.selection.selectedRow].MPAID
1 Like

The error is telling you that you’re using a variable selectedRow but you haven’t defined the value of that variable. I do believe @code_skin has the right idea, but, as you already have selection data available to you, you could do this (assuming props.selection.enableRowSelection and props.selection.enableColumnSelection are both enabled):

val=self.props.selection.data[0]['MPAID']
tag="[default]Perspective/MPAID"
system.tag.writeBlocking(tag,val)
1 Like

Thank you both @code_skin and @cmallonee Appreciate the help!