Script Help-object is not iterable error

I am trying to run this script and I do not understand what the error it gives me. I have listed the error below.

data = system.db.runPrepQuery
(“SELECT ManufacturerUPC, ProductUPC, LabelDesc, Shift, ScaleLine, PalletID, NetWeight, PalletCount, BoxCount, ProductionDate, CompanyCode, SortBy, AddDate FROM tblProductionCounts Where (ScaleLine LIKE ‘041’ or ScaleLine LIKE ‘042’ or ScaleLine LIKE ‘073’) and PalletID = ‘Total’”,[],“Accusort”)
#print data
for row in data:
col1 = row[0]
col2 = row[1]
col3 = row[2]
col4 = row[3]
col5 = row[4]
col6 = row[5]
col7 = row[6]
col8 = int(row[7])
col9 = long(row[8])
col10 = row[9]
col11 = row[10]
col12 = int(row[11])
col13 = row[12]
my_row = “’%s’,’%s’,’%s’,’%s’,’%s’,’%s’,’%s’,%d,%d,’%s’,’%s’,%d,’%s’” %(col1,col2,col3,col4,col5,col6,col7,col8,col9,col10,col11,col12,col13)
stmt = “INSERT INTO Prodotrak_Data (ManufacturerUPC, ProductUPC, LabelDesc, Shift, ScaleLine, PalletID, NetWeight, PalletCount, BoxCount, ProductionDate, CompanyCode, SortBy, AddDate) VALUES (” + my_row + “)”
print stmt
system.db.runPrepUpdate(stmt,[],“JMCProcess”)
trunc_row = my_row[0:-2]
query = "INSERT INTO Prodotrak_Data VALUES " + trunc_row
#print query
system.db.runUpdateQuery(query, “jmcprocess”)

[color=#FF0040]ERROR [ActionAdapter-AWT-EventQueue-2] Error executing script for event: mouseClicked
on component: Button.
Traceback (most recent call last):
File “event:mouseClicked”, line 10, in
TypeError: ‘com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction’ object is not iterable

at org.python.core.Py.TypeError(Py.java:235)
at org.python.core.PyObject.__iter__(PyObject.java:798)
at org.python.pycode._pyx220.f$0(<event:mouseClicked>:31)
at org.python.pycode._pyx220.call_function(<event:mouseClicked>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:554)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:155)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:266)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at com.sun.proxy.$Proxy17.mouseClicked(Unknown Source)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Take a look at the “Dataset” section of the “Working with different Datatypes” section of the manual:

https://ignition.cimarex.com/main/system/help/working_with_different_datatyp.htm?zoom_highlightsub=dataset

The error is because you are trying to iterate through a dataset and a dataset is not iterable.

There are some steps you can take to iterate through the rows and columns however. I copied the code below directly from the manual.

[code]

Pull the dataset property off a Table component

data = event.source.getComponent(“Table”).data

for row in range(data.rowCount):
for col in range(data.columnCount):
print data.getValueAt(row, col)[/code]

The data section is referring to a database I am pulling the data from and dumping it into another database.

Hi there,

You are getting this error because there is an incorrect newline between system.db.runPrepQuery and (“SELECT ManufacturerUPC, ProductUPC, LabelDesc, Shift, ScaleLine, PalletID, NetWeight, PalletCount, BoxCount, ProductionDate, CompanyCode, SortBy, AddDate FROM tblProductionCounts Where (ScaleLine LIKE ‘041’ or ScaleLine LIKE ‘042’ or ScaleLine LIKE ‘073’) and PalletID = ‘Total’”,[],“Accusort”)

Remove the newline between system.db.runQuery and the first parenthesis.

Python is interpreting your code like this:

data = system.db.runPrepQuery
for row in data:
	col1 = row[0]
	...

Instead of running the system.db.runPrepQuery function and returning the results, the system.db.runPrepQuery function itself is being assigned to the variable “data”. And of course a function can’t be iterated. This is occurring because part of the function call is on one line and the rest of the function call (starting with the parenthesis) is on a second line. Put both parts on the same line be removing the newline between them.

On a different issue, is your code indentation really like how you posted it or is it just showing that way on the forum? Indentation needs to be correct in Python.

When posting your code to the forum, you should select ALL of the code from your mouseClicked event.

Then paste it in the Reply textarea.

After that, select the code that you just pasted into the webpage and click the CODE button in the webpage.

This surrounds your code text with this: [code][/code] and ensures it is formatted correctly.

It also helps us determine exactly which line of code (Line 10) generated the error.