# Need to send dataset has payload to mqtt broker

**URL:** <https://forum.inductiveautomation.com/t/need-to-send-dataset-has-payload-to-mqtt-broker/97406>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [October 17, 2024, 4:33pm UTC](https://forum.inductiveautomation.com/t/need-to-send-dataset-has-payload-to-mqtt-broker/97406 "2024-10-17T16:33:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinivasan\_s](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@srinivasan\_s](https://forum.inductiveautomation.com/u/srinivasan_s)\
**Post date:** [October 17, 2024, 4:33pm UTC](https://forum.inductiveautomation.com/t/need-to-send-dataset-has-payload-to-mqtt-broker/97406/1 "2024-10-17T16:33:31Z")

</div>

I am using tag change event to send the alarm data event from DB as dataset - query tag to send to the mqtt broker.  
I am using the below code:

```python
# Step 1: Read the dataset from the tag
tag_path = "[default]LMW/U12/Cylindrical/CMS:Spindle/Alarm" # Replace with your actual tag path
tag_value = system.tag.read(tag_path).value # Read the tag value
# Import the required module
 
import json
# Check if the tag value is a dataset
 
    # Step 2: Convert the dataset to a list of dictionaries
data_as_dicts = []
for i in range(tag_value.getRowCount()):
    row = tag_value.getRow(i)
    data_as_dicts.append(dict(zip(tag_value.getColumnNames(), row)))
    # Convert the list of dictionaries to a JSON string
payload = json.dumps(data_as_dicts)
    # Publish the payload
system.cirruslink.engine.publish("UNS_CMS", "LMW/U1/CYLINDRICAL/L1/CMS:Spindly_Temperature:M001:alarm", payload.encode(), 0, 0)

```

But it not working .  
I query is , is it possible to send the send as dataset to mqtt BROKER?  
If yes , Please help me with this  
**Error I was facing**  
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 14, in AttributeError: 'com.inductiveautomation.ignition.common.BasicDatas' object has no attribute 'getRow'

at org.python.core.Py.AttributeError(Py.java:176)

at org.python.core.PyObject.noAttributeError(PyObject.java:965)

at org.python.core.PyObject. **getattr** (PyObject.java:959)

at org.python.pycode.\_pyx296.f$0(:21)

at org.python.pycode.\_pyx296.call\_function()

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1703)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:804)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:859)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:752)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:840)

at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:251)

at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:198)

at com.inductiveautomation.ignition.common.util.SerialExecutionQueue$PollAndExecute.run(SerialExecutionQueue.java:102)

at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

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 java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: AttributeError: 'com.inductiveautomation.ignition.common.BasicDatas' object has no attribute 'getRow'

... 20 common frames omitted

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [October 17, 2024, 8:13pm UTC](https://forum.inductiveautomation.com/t/need-to-send-dataset-has-payload-to-mqtt-broker/97406/2 "2024-10-17T20:13:03Z")

</div>

Your error is coming from

> [@srinivasan\_s](#):
>
> `row = tag_value.getRow(i)`

`getRow` is not a valid method of a dataset, as noted in the error you posted.

Convert the dataset to a py dataset via `system.dataset.toPyDataSet`, which will allow you to iterate through the rows of the dataset via `for row in tag_value`

Going for mildly compact and readable, your script becomes something along the lines of :

```python
# Read Tag Data
tag_path = "[default]LMW/U12/Cylindrical/CMS:Spindle/Alarm" # Replace with your actual tag path
tag_value = system.tag.read(tag_path).value # Read the tag value

# Get columns of tag dataset
columns = tag_value.columns

# Pack dataset as list of dicts and convert to json
payload = system.util.jsonEncode(
	[zip(columns, row) for row in system.dataset.toPyDataSet(tag_value)]
)

# Publish payload
system.cirruslink.engine.publish("UNS_CMS", "LMW/U1/CYLINDRICAL/L1/CMS:Spindly_Temperature:M001:alarm", payload.encode(), 0, 0)

```
