Hello, I'am executing a SQl query when alarm is actived but it is not working.
This the syntax that I'am using.
system.db.runNamedQuery("SELECT username FROM wind_users WHERE status = 2","DB")
I noticed this when I put a loger after this line of code.
In fact, the lines of code that follow do not execute.
I test on console :
system.db.runNamedQuery("SELECT username FROM wind_users WHERE status = 2")
it is workin.
but on calculated roster not working.
You are passing what looks like an actual SQL statement instead of the name of one of your saved named queries.
I think you should be using
runPrepQuery
not
runNamedQuery
.
runNamedQuery
is for running predefined named queries that are saved in your project.
Specifically, for Gateway scope, it seems that database the name is required, but you're not providing it.
Edit: Additionally, you will need to provide a list of arguments as well (even if it's an empty list in this case).
https://docs.inductiveautomation.com/display/DOC81/system.db.runPrepQuery
I wonder if there's any error message logged to the Gateway about this.
Anyway, the following:
system.db.runPrepQuery("SELECT username FROM wind_users WHERE status = 2", [], dbName)
should be the correct syntax.
EDIT 2: corrected typo in post, should be runPrepQuery not runPredQuery.
Felipe_CRM:
Je me demande s'il y a un message d'erreur enregistré sur la passerelle à ce sujet.
I get that on log:
Logger Time Message
NotificationBlock 05Dec2023 21:22:45 Unable to parse calculated roster.
org.python.core.PyException: AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'runPredQuery'
at org.python.core.Py.AttributeError(Py.java:178)
at org.python.core.PyObject.noAttributeError(PyObject.java:965)
at org.python.core.PyObject.__getattr__(PyObject.java:959)
at org.python.pycode._pyx177.calculateRoster$1(:19)
at org.python.pycode._pyx177.call_function()
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:459)
at org.python.core.PyFunction.__call__(PyFunction.java:454)
at com.inductiveautomation.ignition.alarming.pipelines.blocks.NotificationBlock.getEvaluatedRosterFromScript(NotificationBlock.java:233)
at com.inductiveautomation.ignition.alarming.pipelines.blocks.NotificationBlock.sendNotification(NotificationBlock.java:131)
at com.inductiveautomation.ignition.alarming.pipelines.blocks.NotificationBlock$EvaluationContext.onEvaluate(NotificationBlock.java:374)
at com.inductiveautomation.ignition.alarming.pipelines.blocks.AbstractEvaluationContext.evaluate(AbstractEvaluationContext.java:78)
at com.inductiveautomation.ignition.alarming.pipelines.SingleThreadAlarmPipeline$QueueEvaluator.run(SingleThreadAlarmPipeline.java:187)
at java.base/java.lang.Thread.run(Unknown Source)