How to test whether a tag has alarms configured?

What is the best way to determine whether a tag has any alarms configured (active or not), given a tag path passed as a parameter? I’m trying to show (or hide) an alarm indicator graphic (embedded view) dependent on whether the tag has configured alarms (the tag path is passed as a text parameter to the embedded view).

I have tried using the script below as a transform on a custom property, supplying the tag path for the property binding and checking for existence of the “Alarms” property folder. This actually works but ends up spamming the log with “Error reading path” messages showing the modified path with a “.name” property appended. Note that I don’t ever request the “.name” property. I understand that “Alarms” is a folder containing other properties, not a property itself.

Custom Property Binding:

Log Error:
image

Eventually I transitioned to using an indirect tag binding to an Alarm property for the tag that should only exist if alarms are configured, then performing a !isNull() transform on it. This works and doesn’t create log spam… but this feels hackish.

Revised Custom Property Binding:

I think there must be a better/simpler way that I am just overlooking.

Not perfect, but less hacky:

def hasAlarms(path):
	return len(system.tag.browse(path + "/Alarms/")) > 0

Test if a tag has alarms in an expression:

in a script:

def has_alarms(tag_path):
	return system.tag.readBlocking(["{}.quality".format(tag_path)])[0].value is not None

has_alarms("[]Test/test_pipeline")

>>> True

Another option, if you wanted to search for which tags have alarms configured within a given folder would be doing something like this:

alarmTagList = []
path = '[default]Some/Tag/Folder'
results = system.tag.browse(path).getResults()
for result in results:
	tag = dict(result)
	if 'alarm' in str(tag.get('attributes', '')):
		alarmTagList.append(tag['fullPath'])
return alarmTagList

Though it’s probably a bit overkill for just determining if a single tag has alarms or not.

Calling system.tag.browse is a lot more expensive than binding to a tag and checking if it’s null