Scripting error

The following error is occured by the script below it. Any Ideas?
Error:
Traceback (innermost last):
File “”, line 28, in ?
TypeError: Unable to convert row 5, column 1 to type class java.lang.String

at org.python.core.Py.TypeError(Py.java)
at com.inductiveautomation.factorypmi.application.script.builtin.DBUtilities.toDataSet(DBUtilities.java:233)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyObject.__call__(PyObject.java)
at org.python.core.PyObject.invoke(PyObject.java)
at org.python.pycode._pyx3.f$0(<event>:28)
at org.python.pycode._pyx3.call_function(<event>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.inductiveautomation.factorypmi.application.script.ScriptManager.runCode(ScriptManager.java:227)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:142)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:281)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:54)
at $Proxy1.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.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)

Script:

[code]headers = [“ndx”,“phid”]
data = []
data.append([“DIOCFault”,event.source.parent.DIOCFaultDNC])
data.append([“DISWState1”,event.source.parent.DISWStateDNC])
data.append([“DISWTrip”,event.source.parent.DITripStateDNC])
data.append([“DILocRem1”,event.source.parent.DILocRemDNC])
data.append([“DIAutoOp1”,event.source.parent.DIAutoOpDNC])
data.append([“AIPhaseA”,event.source.parent.AIPhaseAphid])
data.append([“AIPhaseB”,event.source.parent.AIPhaseBphid])
data.append([“AIPhaseC”,event.source.parent.AIPhaseCphid])
data.append([“AIBat”,event.source.parent.AIBatphidDNC])
data.append([“DOSWState”,event.source.parent.DOSWphid])
data.append([“DOLocRem”,event.source.parent.DOLocRemphid])
data.append([“DOAutoOp”,event.source.parent.DOAutoOpphid])
#data.append([])

#ds = event.source.parent.SWControlDataSet
#ds[0,0] = fpmi.db.
#ds[1,0] = event.source.parent.DOphid
if ‘FPMIAdministrator’ in fpmi.security.getRoles():

if fpmi.gui.confirm(‘Are you sure you want to send a control to ’ +event.source.parent.SWName +’?’, ‘Confirm’):

	fpmi.gui.openWindow("SwitchControl",{"DataSet":fpmi.db.toDataSet(headers, data),"SwitchName":event.source.parent.SWName})

else:
fpmi.gui.errorBox(‘Insufficient security privileges.’)[/code]

Hi Qurban,

Please let us know that the datatype of
event.source.parent.DIOCFaultDNC (row zero)
and
event.source.parent.AIPhaseAphid (row five)

Thanks,

event.source.parent.DIOCFaultDNC is a string.
event.source.parent.AIPhaseAphid is an integer.

there’s your problem. A dataset is a table of data. Each column has a name and a datatype. The fpmi.db.toDataSet function uses the first row it sees to determine the datatypes for the columns. So, it is seeing the string on row 0 column 1, and saying “ok, column 1 is a String”.

Then it gets to row 5, and you give it an integer for column 1’s value. It doesn’t like this. You can convert the value to a string manually to make it happy:

Change the line data.append(["AIPhaseA",event.source.parent.AIPhaseAphid]) to data.append(["AIPhaseA",str(event.source.parent.AIPhaseAphid)])

The function shouldn’t be so picky - I’ll make a note of it so that we can make it more lenient in the future.

Hope this helps,

Out of curiosity. What’s that monster script doing?

The script is executed on a ‘mouse click’, which opens another window and the dataset contains the parameters which are passed to the new window. From your(Nathan) comment it seems like this is not the best way to do it. My guess is using the ‘Navigation’ tab under the ‘Action Configuration’ window to pass parameters might be easier. Is that correct?. I inherited the project and am trying to make it work.
From Carls comment it seems like a dataset can contain only one type of variables. Is that Correct?.
Thanks.
Qurban

Yeah, you can pass variables directly using the a navigation script. Each passed variable corresponds to a dynamic property on the root container of the window you’re openening. From your script, it doesn’t look like it makes much sense to pass these variables in a dataset…

Of course, the other window’s bindings are all going to have to be re-done if you decide to re-do it.

A dataSet can contain any number of types of variables. Normally these types are statically defined. If the source is an SQL database, or how you used a Jython script, the column types were determined automatically.

[quote=“qurban”]From Carls comment it seems like a dataset can contain only one type of variables. Is that Correct?.
Thanks.
Qurban[/quote]

For the future, it’s really easy to do as Carl described above. Simple, no scripting necessary!