So I am sending a payload this payload I have also forced the types.
this payload is happening on the editCell event in the table component
def runAction(self, event):
col = str(event['column'])
row = int(event['row'])
value = str(event['value'])
payload = {'row': row, 'col': col, 'editValue': value}
system.perspective.sendMessage('OnEditHandler', payload)
When receiving the payload and trying to use the variables it says the variables have a type of none but when i output the whole payload object i can see there is data inside of them. Because of this when i try to set my array index it says the index needs an integer
def onMessageReceived(self, payload):
#have to update the edited cell here BEFORE we check to see if cells are empty
#something to do with timeings of concurrent updates
system.perspective.print(payload)
editValue = payload['editValue']
col = payload['col']
row = payload['row']
system.perspective.print(type(payload))
system.perspective.print(payload.get('row'))
system.perspective.print(payload.get('col'))
system.perspective.print(payload.get('editValue'))
#for some reason pulling data from the payload throws an error, the code still works and it retains the effect of the code, however it still throws an error
self.view.params.data[row][col].value = editValue
the last line is one causing the issue
specifically the row variable is causing the issue
heres an output of the object
{'col': 'City', 'editValue': 'dfsdfsdsadasdas', 'row': 3}
my param(data) that I am changing is an array of objects
I think your message handler syntax should be,
editValue = payload['editValue']
col = payload['col']
row = payload['row']
Maybe .get()
is supposed to work but I've never seen it used.
Tip: Post formatted code as well as the screenshot so we don't have to type it all out to test or edit it. See Wiki - how to post code on this forum.
gotcha, I'll edit the post thank you for your suggestion. Let me try it real quick
Ok It fixed that issue but now it is having another KeyError issue
com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "<function:onMessageReceived>", line 6, in onMessageReceived
KeyError: 'editValue'
at org.python.core.Py.KeyError(Py.java:224)
at org.python.core.PyObject.__getitem__(PyObject.java:719)
at org.python.pycode._pyx10803.onMessageReceived$1(<function:onMessageReceived>:42)
at org.python.pycode._pyx10803.call_function(<function:onMessageReceived>)
at org.python.core.PyTableCode.call(PyTableCode.java:173)
at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
at org.python.core.PyFunction.function___call__(PyFunction.java:474)
at org.python.core.PyFunction.__call__(PyFunction.java:469)
at org.python.core.PyFunction.__call__(PyFunction.java:464)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:847)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:829)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:868)
at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:1010)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:950)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:161)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:98)
at com.inductiveautomation.perspective.gateway.model.MessageHandlerCollection$MessageHandlerImpl$1.lambda$invoke$0(MessageHandlerCollection.java:86)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at com.inductiveautomation.perspective.gateway.threading.BlockingWork$BlockingWorkRunnable.run(BlockingWork.java:58)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException
Traceback (most recent call last):
File "<function:onMessageReceived>", line 6, in onMessageReceived
KeyError: 'editValue'
... 22 more
Ignition v8.1.40 (b2024051410)
Java: Azul Systems, Inc. 17.0.10
code:
def onMessageReceived(self, payload):
#have to update the edited cell here BEFORE we check to see if cells are empty
#something to do with timeings of concurrent updates
system.perspective.print(payload)
editValue = payload['editValue']
col = payload['col']
row = payload['row']
system.perspective.print(type(payload))
system.perspective.print(type(payload['row']))
system.perspective.print(type(payload['col']))
system.perspective.print(type(payload['editValue']))
#for some reason pulling data from the payload throws an error, the code still works and it retains the effect of the code, however it still throws an error
self.view.params.data[row][col].value = editValue
I had this error before which is why io tried the '.get' method. and it seems to be derived from the types being none again, when i output the types they still return none
EDIT:
I forgot hit apply in the script, I am now getting a type But I am still getting the keyerror.
yes and no, so basically I am allowing the user to change data on a table however if they fill out the last row I want to add an empty row so they may submit more data.
I am accomplishing this by having the runAction happen when the editCellCommit event is fired, it sends a message via messagehandler with the payload.
I am then taking a message handler on the table inside of a view and whenever it is fired I am running code to update the value the user just changed and then check to see if they should add an empty row.
the onMessageReceived handler is on a table inside of a view, I am referencing this table many times as my program is for configuration so it will take alot of inputs
your question has brought clarity to my mind I dont know why i was funneling the info through so many tunnels I ended up just putting all the code on the editCellCommit event and it works with no errors. The only issue is if the table Already has data in it starting out then it does not auto populate a row.
code if your curious:
def runAction(self, event):
#have to update the edited cell here BEFORE we check to see if cells are empty
#something to do with timeings of concurrent updates
editValue = event['value']
col = event['column']
row = event['row']
#for some reason pulling data from the payload throws an error, the code still works and it retains the effect of the code, however it still throws an error
self.view.params.data[row][col].value = editValue
value = self.view.params.data
#see if it is an auto adding table
if(self.view.params.keepAddingRows == True):
threshold = len(self.view.params.NUmberOfColumns)
#test to see if last entry in table is empty
#if it is dont add, if it is add an empty entry
amountOfRows = len(self.view.params.data)
system.perspective.print(amountOfRows)
count = 0
for index, entry in enumerate(self.view.params.NUmberOfColumns):
colName = entry.field
if(self.view.params.data[amountOfRows-1][colName].value != ''):
count+=1
if(threshold == count):
tempObject = {}
for i in range(threshold):
tempObject[self.view.params.NUmberOfColumns[i].field] = {'value': '', 'editable': True}
system.perspective.print(tempObject)
system.perspective.print(value)
value.append(tempObject)
self.props.data = value
else:
self.props.data = value
else:
self.props.data = value
thank you for your questions they helped me realize my errors thanks!
2 Likes
That's what I reckoned should be taking place. I can sleep easy now!
Tip:
if(self.view.params.keepAddingRows == True):
can be reduced to,
if self.view.params.keepAddingRows:
1 Like
thank you, always excited to optimize code!