# Get Source of Each Alarm from QueryStatus

**URL:** <https://forum.inductiveautomation.com/t/get-source-of-each-alarm-from-querystatus/81613>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [November 7, 2023, 6:39pm UTC](https://forum.inductiveautomation.com/t/get-source-of-each-alarm-from-querystatus/81613 "2023-11-07T18:39:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 7, 2023, 6:39pm UTC](https://forum.inductiveautomation.com/t/get-source-of-each-alarm-from-querystatus/81613/1 "2023-11-07T18:39:47Z")

</div>

I've got this script in the console that gets me what I want, but I don't want to just print it, I want to store it in a list of strings.

```auto
#get the list of all acknowledged alarms
alms = system.alarm.queryStatus(state=["ActiveAcked"])

#initialize empty list of sources
sources = []

#active ack'd alarms count is non-zero
if alms is not None:
	#for each alarm, get the source path and add it to the list
	for alm in alms:
		print alm.source

```

but whenever I try to cast the source path to a string or assign it to a variable I get the error `NameError: name 'source' is not defined`

```auto
#get the list of all acknowledged alarms
alms = system.alarm.queryStatus(state=["ActiveAcked"])

#initialize empty list of sources
sources = []

#active ack'd alarms count is non-zero
if alms is not None:
	#for each alarm, get the source path and add it to the list
	for alm in alms:
		sources.append(str(alm.source))

```

_Of course now that I post it here I don't get an error..._

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 7, 2023, 7:00pm UTC](https://forum.inductiveautomation.com/t/get-source-of-each-alarm-from-querystatus/81613/2 "2023-11-07T19:00:12Z")

</div>

This is a classic case for a list comprehension, for what it's worth:

```python
sources = [str(alm.source) for alm in system.alarm.queryStatus(state=["ActiveAcked"])]

```

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 7, 2023, 7:00pm UTC](https://forum.inductiveautomation.com/t/get-source-of-each-alarm-from-querystatus/81613/3 "2023-11-07T19:00:58Z")

</div>

Getting better at list comprehension, but I don't always spot it right out of the gate.

How does this handle the null list?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 7, 2023, 7:02pm UTC](https://forum.inductiveautomation.com/t/get-source-of-each-alarm-from-querystatus/81613/4 "2023-11-07T19:02:45Z")

</div>

_Can_ queryStatus return null? Most of our functions that return a list are pretty good about returning an empty list if there's no values, not an outright null.

You're right that my implementation wouldn't handle it if it were somehow null.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 7, 2023, 7:45pm UTC](https://forum.inductiveautomation.com/t/get-source-of-each-alarm-from-querystatus/81613/5 "2023-11-07T19:45:46Z")

</div>

> [@paul-griffith](#):
>
> _Can_ queryStatus return null?

Great question, not sure but I have that catch in there to make sure if there ever was a null that I'd get an empty list instead. I noticed that a new string array tag had value null, so I just reminded me to check for that.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [November 7, 2023, 8:06pm UTC](https://forum.inductiveautomation.com/t/get-source-of-each-alarm-from-querystatus/81613/6 "2023-11-07T20:06:18Z")

</div>

Since this is a query, is there a way to order the results outside of doing it in python after I have the list? And on that note, how is the order determined?

I ask because there's a button on the screen that stores the current list of Active and Acknowledged alarms and I want to be able to compare that stored list against the active list and I need to know when there's a difference. Right now I'm using

```auto
ackdALMs,knownAckdALMs = system.tag.readBlocking(['[default]Alarms/Remote Reset/ackdALMs','[default]Alarms/Remote Reset/ackdALMs_known'])
	return not ackdALMs.value == knownAckdALMs.value

```

but that may not work if the order is not always the same
