# Payload return objects have NoneType on MessageHandler

**URL:** <https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 19, 2024, 7:01pm UTC](https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116 "2024-06-19T19:01:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [June 19, 2024, 7:01pm UTC](https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116/1 "2024-06-19T19:01:35Z")

</div>

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

```python
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

```python
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

```python
{'col': 'City', 'editValue': 'dfsdfsdsadasdas', 'row': 3}

```

my param(data) that I am changing is an array of objects

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 19, 2024, 7:40pm UTC](https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116/2 "2024-06-19T19:40:19Z")

</div>

I think your message handler syntax should be,

```python
    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](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [June 19, 2024, 7:44pm UTC](https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116/3 "2024-06-19T19:44:55Z")

</div>

gotcha, I'll edit the post thank you for your suggestion. Let me try it real quick

---

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [June 19, 2024, 7:51pm UTC](https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116/4 "2024-06-19T19:51:25Z")

</div>

Ok It fixed that issue but now it is having another KeyError issue

```python
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:

```python
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.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 19, 2024, 8:08pm UTC](https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116/5 "2024-06-19T20:08:05Z")

</div>

Step back a bit.

- The run action is on a table's `onEditCellCommit` event?
- Where is the `onMessageReceived` message handler?

---

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [June 19, 2024, 8:14pm UTC](https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116/6 "2024-06-19T20:14:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [June 19, 2024, 8:28pm UTC](https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116/7 "2024-06-19T20:28:22Z")

</div>

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:

```python
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!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 19, 2024, 9:02pm UTC](https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116/8 "2024-06-19T21:02:24Z")

</div>

> [@Matthew\_Breeding](#):
>
> I ended up just putting all the code on the editCellCommit event ...

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:`

---

<div class="post-metadata">

**Author:** ![Matthew\_Breeding](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@Matthew\_Breeding](https://forum.inductiveautomation.com/u/Matthew_Breeding)\
**Post date:** [June 19, 2024, 11:17pm UTC](https://forum.inductiveautomation.com/t/payload-return-objects-have-nonetype-on-messagehandler/92116/9 "2024-06-19T23:17:21Z")

</div>

thank you, always excited to optimize code!
