Hi all,
I'm working on a simple calculated roster to get my feet wet with how these system work. I'm running a simple named query with no parameters and trying to use that data to create a simple user to send an email. The email system does work but the roster itself is not working as I think it is.
Error:
Code:
I'm sure its a simple error, I'm just not familiar with alarming.
Thank you,
Cam
The error comes from the very first line. You're trying to call event.name
, which is a string.
That said, once that's fixed, you still won't get what you expect.
The loop is returning a single user, which I doubt is what you want.
You need to return after the loop is complete, not inside it.
Hi,
I was able to make it work with the following code:
def calculateRoster(event, builder):
# get the alarm name property
alarmName = event.getName()
if alarmName in ["Diagnostic Alarm"]:
# return an empty list so no one will be emailed
return []
else:
# get user information from the database
#data = system.db.runNamedQuery("get_AlarmInformation")
data = system.db.runPrepQuery("SELECT wa_users.username, wa_user_ci.contact_type, wa_user_ci.contact_value FROM wa_user_ci INNER JOIN wa_users ON wa_users.id = wa_user_ci.user_id")
for row in data:
if row['contact_type'] == "email":
builder.username(row['username']).email([row['contact_value']]).add()
userList = builder.build()
return userList
However, I'd rather have it run the named query so all my queries are encapsulated in one location. If I un-comment the namedQuery I get this error:
org.python.core.PyException: java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Project name required for script execution: the Gateway Scripting Project is not set.
at org.python.core.Py.JavaError(Py.java:547)
at org.python.core.Py.JavaError(Py.java:538)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:552)
at org.python.core.PyObject.__call__(PyObject.java:461)
at org.python.core.PyObject.__call__(PyObject.java:465)
at org.python.pycode._pyx2755.calculateRoster$1(:20)
at org.python.pycode._pyx2755.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)
Caused by: java.lang.IllegalArgumentException: Project name required for script execution: the Gateway Scripting Project is not set.
at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.interpretWithOptionalProject(GatewayDBUtilities.java:476)
at com.inductiveautomation.ignition.gateway.script.GatewayDBUtilities.runNamedQuery(GatewayDBUtilities.java:391)
at jdk.internal.reflect.GeneratedMethodAccessor81.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)
... 17 common frames omitted
As alarm notifications are in the gateway scope you have to pass the project path as a parameter in your named query.
Along with converting it to a PyDataset so that you can iterate through it
data = system.db.runNamedQuery("WorkingAlone_V2","get_AlarmInformation")
data = system.dataset.toPyDataSet(data)