# Pass Alarm Associated Data as Query Parameter

**URL:** <https://forum.inductiveautomation.com/t/pass-alarm-associated-data-as-query-parameter/62714>\
**Category:** Ignition\
**Tags:** scripting, ignition81\
**Created:** [August 5, 2022, 11:54am UTC](https://forum.inductiveautomation.com/t/pass-alarm-associated-data-as-query-parameter/62714 "2022-08-05T11:54:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [August 5, 2022, 11:54am UTC](https://forum.inductiveautomation.com/t/pass-alarm-associated-data-as-query-parameter/62714/1 "2022-08-05T11:54:51Z")

</div>

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:

```auto
	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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 5, 2022, 12:00pm UTC](https://forum.inductiveautomation.com/t/pass-alarm-associated-data-as-query-parameter/62714/2 "2022-08-05T12:00:20Z")

</div>

Try:

```auto
	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.

---

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [August 5, 2022, 12:08pm UTC](https://forum.inductiveautomation.com/t/pass-alarm-associated-data-as-query-parameter/62714/3 "2022-08-05T12:08:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [August 5, 2022, 1:11pm UTC](https://forum.inductiveautomation.com/t/pass-alarm-associated-data-as-query-parameter/62714/4 "2022-08-05T13:11:23Z")

</div>

I just checked the log (I forgot it exists) to see why it didn’t work and it says:

```auto
org.python.core.PyException: Traceback (most recent call last): File "", line 21, in calculateRoster NameError: global name 'alarmEvent' is not defined

```

---

<div class="post-metadata">

**Author:** ![jwilliams](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@jwilliams](https://forum.inductiveautomation.com/u/jwilliams)\
**Post date:** [August 5, 2022, 2:07pm UTC](https://forum.inductiveautomation.com/t/pass-alarm-associated-data-as-query-parameter/62714/5 "2022-08-05T14:07:12Z")

</div>

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.

```auto
	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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 5, 2022, 2:17pm UTC](https://forum.inductiveautomation.com/t/pass-alarm-associated-data-as-query-parameter/62714/6 "2022-08-05T14:17:04Z")

</div>

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. )
