I have associated data on an alarm, it is static, but different for each tag the alarm exists on. The associated data is called JobNumber. I also have an Alarm Notification Pipeline using a calculated roster type with a script to run a named query, but I cannot get my alarm associated data to pass correctly as a parameter into the runNamedQuery. Here is what my script looks like:
params = alarmEvent.get("JobNumber")
data = system.db.runNamedQuery("ALARM QUERY", {params})
for row in data:
builder.username(row["username"]).email([row["emailaddress"]]).add()
roster = builder.build()
return roster
The NamedQuery has a parameter field to accept an integer and the JobNumber associated data is also an integer which is what I am trying to pass. I think that the first line where I call to get the associated data is what is causing the issue but I do not know the correct syntax for it.
Try:
param = alarmEvent.get("JobNumber")
data = system.db.runNamedQuery("ALARM QUERY", {'JobNumber': param})
Just putting curly braces around a variable doesn’t make it a dictionary.
1 Like
That did not work, but I see what you mean about the dictionary. I’m pretty sure I got this to work sometime yesterday, but I wasnt paying attention to my email I use to test the notification block and missed it and then ended up changing the code and cant remember how I did it.
I just checked the log (I forgot it exists) to see why it didn’t work and it says:
org.python.core.PyException: Traceback (most recent call last): File "", line 21, in calculateRoster NameError: global name 'alarmEvent' is not defined
Wanted to post this as I figured out how to get the query to allow parameters, just not with a Named Query like I was trying. I had to use a Prep Query.
params = event["Number"]
data = system.db.runPrepQuery("SELECT * FROM table WHERE job = ?",[params])
The event[“Number”] is the name of the associated data from the alarm.
That is also not the actual query I am running but for ease of understanding I trimmed it to make it simpler here.
Ah, probably because runNamedQuery
requires a project name when called in gateway scope, even if in a project. ( Longstanding API screw-up that isn’t readily fixable. )
1 Like