# Issue getting label of alarm?

**URL:** <https://forum.inductiveautomation.com/t/issue-getting-label-of-alarm/86850>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [March 5, 2024, 7:09pm UTC](https://forum.inductiveautomation.com/t/issue-getting-label-of-alarm/86850 "2024-03-05T19:09:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 5, 2024, 7:09pm UTC](https://forum.inductiveautomation.com/t/issue-getting-label-of-alarm/86850/1 "2024-03-05T19:09:17Z")

</div>

Using 8.1.26.

Was helping a coworker create a report of alarms similar to from my post from a few years back -  
[Creating report from alarm data - getting user who acknowledged alarm and when? - Ignition - Inductive Automation Forum](https://forum.inductiveautomation.com/t/creating-report-from-alarm-data-getting-user-who-acknowlegded-alarm-and-when/60450/7)

In this report we wanted to show the label of the alarm -

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/2/c291d76931f225e40c22ddeced2c9321e6cf7270.png)

So in this part

```auto
allAlarmData = system.alarm.queryJournal(journalName='BypassJournal', startDate=beginningOfDay, endDate=endOfDay, includeSystem=False)

dictOut = {}

# Set key names for datapoints associated with each UUID
keys = ['active', 'cleared', 'name']

for alarmRecord in allAlarmData:
	eventTime = alarmRecord.get(CommonAlarmProperties.EventTime)
	alarmActive = alarmRecord.get(CommonAlarmProperties.ActiveTime)
	alarmCleared = alarmRecord.get(CommonAlarmProperties.ClearTime)
	alarmName = alarmRecord.get(CommonAlarmProperties.DisplayPath)
	uuid = alarmRecord.id
	# GET LABEL
	alarmLabel = alarmRecord.get(CommonAlarmProperties.Label)

```

Using for some reason only ever returned `None`. I also then tried `alarmRecord.label` but that returned `u'Alarm'`. I wonder if it has something to do with how I configured the alarm - it's in a UDT and is like this -

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/4/a4ea64fdd31722eae6b6b442209b1d61132ae4ea.png)

where `CL.getalarmLabel` does a `.get` on a top level dictionary object This works for viewing the alarm label in the status table and journal table but I seem to be doing it incorrectly in the script. I must be missing something simple but I can't figure it out. What is going wrong?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 5, 2024, 7:30pm UTC](https://forum.inductiveautomation.com/t/issue-getting-label-of-alarm/86850/2 "2024-03-05T19:30:27Z")

</div>

Perhaps try the legacy style for calling `runScript` and see if that doesn't give you a different result?

```auto
runScript("CL.getAlarmLabel('" + {InstanceName} + "')",0)

```

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 5, 2024, 7:36pm UTC](https://forum.inductiveautomation.com/t/issue-getting-label-of-alarm/86850/3 "2024-03-05T19:36:37Z")

</div>

I was suspecting it has something to do with the `runScript`. I recall an issue where I tried to use a `runScript` to generate the body of an email in a scheduled report and it was emailing the text runScript("Blah")` instead of executing. It does seem odd since it is coming through correctly on my alarm status and journal tables. Not that reporting and alarms modules are related but that runScript is prone to wonkiness in certain contexts.

I am considering making a dataset and using a `lookup` expression instead and perhaps that will fair better as well.

It should be `alarmLabel = alarmRecord.get(CommonAlarmProperties.Label)` or `alarmRecord.label` right? That part is correct?

---

<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:** [March 5, 2024, 7:44pm UTC](https://forum.inductiveautomation.com/t/issue-getting-label-of-alarm/86850/4 "2024-03-05T19:44:04Z")

</div>

Is the label actually being stored into the journal for the event(s) in question?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 5, 2024, 7:48pm UTC](https://forum.inductiveautomation.com/t/issue-getting-label-of-alarm/86850/5 "2024-03-05T19:48:42Z")

</div>

`alarmLabel = alarmRecord.label` should work. (I would probably just do this).

Assuming you've imported `CommonAlarmProperties` somewhere in scope, then `alarmRecord.get(CommonAlarmProperties.Label)` should also work.

As long as the label is being stored to the journal. Since you're seeing it in the AlarmJournal table, I would also expect it to work.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 5, 2024, 8:49pm UTC](https://forum.inductiveautomation.com/t/issue-getting-label-of-alarm/86850/6 "2024-03-05T20:49:10Z")

</div>

Seems like it is -

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/f/4ff901ad9992d1d908b19cb6d9cf79797f376255.jpeg)

Here's my attempt using the `alarmRecord.label`  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/3/93a7d36314ba9be6f7f6c9a84026488becc333f4.png). The ones with CL 14, 5, 2 i would have expected something other than Alarm.

Feels weird since at this point its in the journal it's in a db and this should just be getting queried directly. So I suspect it's something in the script so here is my coworkers full script -

```auto
from com.inductiveautomation.ignition.common.alarming.config import CommonAlarmProperties 

start = '2022-06-04 00:00:00'
end = '2022-06-06 00:00:00'

beginningOfDay = system.date.parse(start)
endOfDay = system.date.parse(end)

allAlarmData = system.alarm.queryJournal(journalName='BypassJournal', startDate=beginningOfDay, endDate=endOfDay, includeSystem=False)

dictOut = {}

# Set key names for datapoints associated with each UUID
keys = ['active', 'cleared', 'name', 'label']

for alarmRecord in allAlarmData:
	# Get Data points
	eventTime = alarmRecord.get(CommonAlarmProperties.EventTime)
	alarmActive = alarmRecord.get(CommonAlarmProperties.ActiveTime)
	alarmCleared = alarmRecord.get(CommonAlarmProperties.ClearTime)
	# Note that I use displaypath instead of name. To each their own. ;)
	# alarmName = alarmRecord.getName()
	alarmName = alarmRecord.get(CommonAlarmProperties.DisplayPath)
        alarmLabel = alarmRecord.label
	# The UUID is what ties it all together.
	uuid = alarmRecord.id
	
	# Chech if the UUID exists. Make an entry for it if it does not.
	if uuid not in dictOut.keys():
		# Keys full of Nones.  
		dictOut[uuid] = {key:None for key in keys}
	# Set the alarm name, if it doesn't exist
	if not dictOut[uuid]['name']:
		dictOut[uuid]['name'] = alarmName	
     	if not dictOut[uuid]['label']:
		dictOut[uuid]['label'] = alarmLabel
	# Set the alarm active time, if it doesn't exist
	if alarmActive and not dictOut[uuid]['active']:
		dictOut[uuid]['active'] = alarmActive
	# Set the alarm cleared time, if it doesn't exist
	if alarmCleared and not dictOut[uuid]['cleared']:
		dictOut[uuid]['cleared'] = alarmCleared

headers = ['Alarm Occured At', 'Alarm Cleared At', 'Alarm Name', 'Alarm Description']
rows = []
for values in dictOut.values():
	rows.append([values[key] for key in keys])

# Create the dataset
dataset = system.dataset.sort(system.dataset.toDataSet(headers, rows), 'Alarm Occured At')
# Print to file etc
util.printDataSet(dataset)

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 5, 2024, 9:06pm UTC](https://forum.inductiveautomation.com/t/issue-getting-label-of-alarm/86850/7 "2024-03-05T21:06:50Z")

</div>

Do the following and see what is returned:

```auto
alarmLabel = alarmRecord.getOrElse(CommonAlarmProperties.Label,'No Label Provided')

```

You can also use

```auto
alarmRecord.contains(CommonAlarmProperties.Label)

```

to see if the record contains a Label.

You should also be able to use `alarmRecord.properties` to get a list of all properties on the record, which "should" be able to point you towards what actually has the value you're looking for.
