Issue getting label of alarm?

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

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

So in this part

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 -

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?

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

runScript("CL.getAlarmLabel('" + {InstanceName} + "')",0)
1 Like

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?

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

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.

Seems like it is -

Here's my attempt using the alarmRecord.label
image. 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 -

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)

Do the following and see what is returned:

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

You can also use

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.

2 Likes