Hi all. I am still new to the ignition software and its scripting functionality. I'm attempting edit a Boolean value through the perspective table component and have it write back to the database.
Im using a script under the "event: onEditCellCommit" that looks like this:
I created columns in my table that are set to editable
and i also was sure to activate the "enableRowSelection" and "enableColumnSelection" attributes.
The database connection is working as I've been able to add rows and query them, however when I try to edit the isActive columns bool value in my table (which looks like this):
I'm presented with this error.
How can I go about fixing this issue and if possible could someone explain my oversight to me so I can more fully understand what it is I'm trying to do vs what I'm actually doing.
Thank you,
Cam
First off, event.source.data is a dataset, not a pyDataset. You have to convert to a pyDataset to use indexes using system.dataset.toPyDataSet()
. That doesn't solve your problem though. You have to actually run a named query, or a prep update to modify the database to keep the change.
I don't think that's correct. This code works for me in Designer and prints the correct value out to Output Console.
def runAction(self, event):
self.props.data[event.row][event.column] = event.value
system.perspective.print(self.props.data[event.row][event.column])
Result:
20:53:34.328 [Browser Thread: 51737] INFO Perspective.Designer.Workspace - true
20:53:34.880 [Browser Thread: 51737] INFO Perspective.Designer.Workspace - false
1 Like
oof, I flashed back to Vision. Gotta reboot...
1 Like
Is there any more on the Details tab?
Tip post the errors as text formatted with the </> button rather than post as a screengrab. The important bit is probably at the end of the first line.
com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "function:runAction", line 2, in runAction
TypeError: 'com.inductiveautomation.ignition.gateway.datasource.BasicStreamingDataset' object is unsubscriptable
at org.python.core.Py.TypeError(Py.java:236)
at org.python.core.PyObject.__finditem__(PyObject.java:653)
at org.python.core.PyObjectDerived.__finditem__(PyObjectDerived.java:920)
at org.python.core.PyObject.__getitem__(PyObject.java:717)
at org.python.core.PyObjectDerived.__getitem__(PyObjectDerived.java:960)
at org.python.pycode._pyx13.runAction$1(<function:runAction>:3)
at org.python.pycode._pyx13.call_function(<function:runAction>)
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:846)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:828)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:832)
at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:1009)
at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:897)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:158)
at com.inductiveautomation.perspective.gateway.script.ScriptFunctionHelper.invoke(ScriptFunctionHelper.java:97)
at com.inductiveautomation.perspective.gateway.action.ScriptAction.runAction(ScriptAction.java:74)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.lambda$call$0(ActionCollection.java:263)
at com.inductiveautomation.perspective.gateway.api.LoggingContext.mdc(LoggingContext.java:54)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:252)
at com.inductiveautomation.perspective.gateway.model.ActionCollection$ActionSequence$ExecuteActionsTask.call(ActionCollection.java:221)
at com.inductiveautomation.perspective.gateway.threading.BlockingTaskQueue$TaskWrapper.run(BlockingTaskQueue.java:154)
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 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:runAction", line 2, in runAction
TypeError: 'com.inductiveautomation.ignition.gateway.datasource.BasicStreamingDataset' object is unsubscriptable
... 31 more
Ignition v8.1.27 (b2023042509)
Java: Azul Systems, Inc. 11.0.18\
I think this is what youre asking for. If not could you give me more specific steps so I can get exactly what you need?
Datasets aren't directly mutable.
You need to change your script to something like:
self.props.data = system.dataset.setValue(self.props.data, event.row, event.column, event.value)
Or change your query return type to JSON so that the table data is "exploded" into a JSON like format this is directly mutable.
Note that doing either of those things will still only update the local data. If you want to update the actual table in your database, you need a more involved script; you should run an UPDATE query from onEditCellCommit
and then refresh("props.data")
once you've issue the update.
Thank you very much! The first part of this was very clear, the second part I'm a little unclear on. How would I go about writing the update query in the event scripting section? Also what do you mean by refresh("props.data"), and how do I do that in the script?
I like to use named queries with system.db.runNamedQuery.
You can refresh the table like this:
self.getSibling("Table").refreshBinding("props.data")
2 Likes
Thank you very much! That answers all my questions
1 Like