# Alarm Table Filter Script

**URL:** <https://forum.inductiveautomation.com/t/alarm-table-filter-script/63606>\
**Category:** Ignition\
**Created:** [August 30, 2022, 2:46pm UTC](https://forum.inductiveautomation.com/t/alarm-table-filter-script/63606 "2022-08-30T14:46:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Frei](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Matthew\_Frei](https://forum.inductiveautomation.com/u/Matthew_Frei)\
**Post date:** [August 30, 2022, 2:46pm UTC](https://forum.inductiveautomation.com/t/alarm-table-filter-script/63606/1 "2022-08-30T14:46:22Z")

</div>

Hello All!

Disclaimer, I’m VERY new to Ignition, but not HMI programming. I have been steadily working my way through the university training videos/tests, and trying to apply some version of each lesson in a sample project. I’m currently stuck on the Alarm Table Filtering based on associated tags…

When I apply my script, instead of filtering the alarms, it makes them ALL disappear. I’ve tried filtering on both “priority” and a custom tag called “group”. My script for priority is as follows:

def filterAlarm(self, alarmEvent):

```
Priority = alarmEvent.get("priority")

if Priority == "Critical" or Priority == "High":
	return True
else:
        return False

```

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

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

The idea is to have 2 fault banners at the top of my display. One will ONLY show the higher level alarms, the other showing ONLY medium-low level. However, every alarm is disappearing when the script is applied. When I disable the filter script, the alarms come back immediately. This exact case is happening when using the custom tag “group”.

Any assistance is appreciated,  
Thank you!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 30, 2022, 3:05pm UTC](https://forum.inductiveautomation.com/t/alarm-table-filter-script/63606/2 "2022-08-30T15:05:39Z")

</div>

Why not use the built-in priority filters ?

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

About your issue: You're comparing a priority object with a string. This will not work.  
Two solutions here:

- get the string value of the priority (or its int value):

```python
alarmEvent.priority.toString() == "Critical"
alarmEvent.priority.intValue() == 4

```

- use the class attributes (I suggest using this):

```python
alarmEvent.priority == alarmEvent.priority.Critical

```

example I ran in a script console:

```python
data = system.alarm.queryStatus()

priority = data[0].priority

priority.toString() == "High"
priority.intValue >= 2
priority < data[0].priority.Critical

```

> True  
> True  
> True

Note: You can use the `>`, `>=`, `<=` and `<` operators too when using the int value or the class attributes.

---

<div class="post-metadata">

**Author:** ![Matthew\_Frei](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Matthew\_Frei](https://forum.inductiveautomation.com/u/Matthew_Frei)\
**Post date:** [August 30, 2022, 3:25pm UTC](https://forum.inductiveautomation.com/t/alarm-table-filter-script/63606/3 "2022-08-30T15:25:35Z")

</div>

Converting the .get(“Priority”) to a string before my compare worked.

def filterAlarm(self, alarmEvent):

```
Priority = alarmEvent.get("Priority").toString()

if Priority == "Critical" or Priority == "High":
	return True
else:
    return False

```

I dont have the filters you showed… perhaps I have the wrong properties open…? Trying to find one in view that actually opens hasnt been successful either… but that would be FAR easier than a script…

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/8/987a361d95b1cbe0f82035321d5950d52a05f190.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/c/8c9db10cde4703e7b96bdfacdef1ca538be6cea3.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 30, 2022, 3:31pm UTC](https://forum.inductiveautomation.com/t/alarm-table-filter-script/63606/4 "2022-08-30T15:31:53Z")

</div>

That’s because you’re using vision, and I’m using perspective.  
I don’t know anything about vision.

I’d suggest reworking your script like this:

```auto
priority = alarmEvent.priority
return priority >= priority.High

```

You don’t need the if/else statement, as the comparison already returns a boolean.  
And using the class attribute allows you to use `>=` and check for both high and critical alarms at once, instead of having 2 conditions.

---

<div class="post-metadata">

**Author:** ![Matthew\_Frei](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Matthew\_Frei](https://forum.inductiveautomation.com/u/Matthew_Frei)\
**Post date:** [August 30, 2022, 3:41pm UTC](https://forum.inductiveautomation.com/t/alarm-table-filter-script/63606/5 "2022-08-30T15:41:23Z")

</div>

Great suggestion!

Thank you!
