Need to send dataset has payload to mqtt broker

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:

# 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

Your error is coming from

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 :

# 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)