# How to Highlight Navigation Buttons Based on Active Alarms in Ignition

**URL:** <https://forum.inductiveautomation.com/t/how-to-highlight-navigation-buttons-based-on-active-alarms-in-ignition/98524>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [November 12, 2024, 4:56pm UTC](https://forum.inductiveautomation.com/t/how-to-highlight-navigation-buttons-based-on-active-alarms-in-ignition/98524 "2024-11-12T16:56:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Lino](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@Jose\_Lino](https://forum.inductiveautomation.com/u/Jose_Lino)\
**Post date:** [November 12, 2024, 4:56pm UTC](https://forum.inductiveautomation.com/t/how-to-highlight-navigation-buttons-based-on-active-alarms-in-ignition/98524/1 "2024-11-12T16:56:44Z")

</div>

Hello everyone,

I'm working on a project where I need to highlight navigation buttons if there is an active alarm on the corresponding screen. For example, if there is an active alarm on Screen 3, the button that navigates to Screen 3 should be highlighted.

The tags and folders are organized by screen, so I plan to highlight the buttons by checking all the alarms in the respective folders.

I have experience with Python, but I'm relatively new to scripting in Ignition. So far, I've only worked with alarm filters and simple display logic.

Here’s a sample code snippet I came up with (note: I haven't tested this yet). I'm not sure if I should add this script to each button individually or in the script console. Could you please advise on the necessary changes and where to implement this code?

```python
# Function to check for active alarms in a specific screen
def check_active_alarms(screen_folder):
    alarms = system.alarm.queryStatus(path=["*[default]Sensors/*"])
    return len(alarms) > 0

# Function to update button style
def update_button_style(button, active):
    if active:
        button.background = "red"
    else:
        button.background = "default" 

# Function to update all navigation buttons
def update_navigation_buttons():
    screen_buttons = {
        "Screen1": screen1_button,
        "Screen2": screen2_button,
        "Screen3": screen3_button,
    }

    # Check alarms and update button styles
    for screen_folder, button in screen_buttons.items():
        alarms_active = check_active_alarms(screen_folder)
        update_button_style(button, alarms_active)

update_navigation_buttons()

```

Should I use this script in the Script Console or on each individual button? Are there any improvements or best practices I should follow?

Thank you in advance for your help!

---

<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:** [November 12, 2024, 5:04pm UTC](https://forum.inductiveautomation.com/t/how-to-highlight-navigation-buttons-based-on-active-alarms-in-ignition/98524/2 "2024-11-12T17:04:03Z")

</div>

Broadly speaking, store the results of `check_active_alarms` somewhere that's globally accessible, then bind your buttons' styles to that.

In more details, I'd probably have a single dataset tag to store that information, and I'd write to that tag with a timer script. The time step depends entirely on your accuracy needs.  
Then a simple expression using `lookup` on that dataset tag will tell you whether there are active alarms for a particular entry.

note that as it is, your `check_active_alarms` function doesn't use the `screen_folder` parameter, so you'll get the same result for each button, which is probably not what you want.

---

<div class="post-metadata">

**Author:** ![Jose\_Lino](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@Jose\_Lino](https://forum.inductiveautomation.com/u/Jose_Lino)\
**Post date:** [November 12, 2024, 6:17pm UTC](https://forum.inductiveautomation.com/t/how-to-highlight-navigation-buttons-based-on-active-alarms-in-ignition/98524/3 "2024-11-12T18:17:18Z")

</div>

Thanks for the response!

What do you mean by a single dataset and to write to a tag with a timer script?

Thanks for the note!

Is there an easier way to do it?

I discovered that I can use `isAlarmActive('[default]Path/To/UDT*')` , but is there a way to specify only the path and not a specific tag? I want to work with all the tags in a folder, not just a single tag.

---

<div class="post-metadata">

**Author:** ![Jose\_Lino](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@Jose\_Lino](https://forum.inductiveautomation.com/u/Jose_Lino)\
**Post date:** [November 12, 2024, 7:44pm UTC](https://forum.inductiveautomation.com/t/how-to-highlight-navigation-buttons-based-on-active-alarms-in-ignition/98524/4 "2024-11-12T19:44:27Z")

</div>

I did the following code. It is not working, and I can't figure out why.

```python
pathValue = "prov:default:/tag:Sensors/*" # Folder path
alarms = system.alarm.queryStatus(source=pathValue, state=[2, 3]) 

for alarm in alarms:
    if alarm.state in [2, 3]: # Check for ActiveUnacked or ActiveAcked
        event.source.buttonBG = 255,0,0
        break  

```

---

<div class="post-metadata">

**Author:** ![Jose\_Lino](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@Jose\_Lino](https://forum.inductiveautomation.com/u/Jose_Lino)\
**Post date:** [November 13, 2024, 2:29pm UTC](https://forum.inductiveautomation.com/t/how-to-highlight-navigation-buttons-based-on-active-alarms-in-ignition/98524/6 "2024-11-13T14:29:50Z")

</div>

I’m not sure how it happened, but it appears that your post was deleted.

Here’s your original comment:

" I can't say its the answer to all of your questions but I don't think this works:

```python
event.source.buttonBG = 255,0,0

```

Try something like this instead:

```python
event.source.backgroundColor = "#FF0000"

```

Since you are querying for only status 2,3, your if statement is redundant."

---

<div class="post-metadata">

**Author:** ![Jose\_Lino](https://avatars.discourse-cdn.com/v4/letter/j/87869e/32.png) [@Jose\_Lino](https://forum.inductiveautomation.com/u/Jose_Lino)\
**Post date:** [November 13, 2024, 2:31pm UTC](https://forum.inductiveautomation.com/t/how-to-highlight-navigation-buttons-based-on-active-alarms-in-ignition/98524/7 "2024-11-13T14:31:48Z")

</div>

Am I declaring the function in the right place? I created a custom function in the component script.

I tried in different places, but it didn't work.

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

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [November 13, 2024, 4:25pm UTC](https://forum.inductiveautomation.com/t/how-to-highlight-navigation-buttons-based-on-active-alarms-in-ignition/98524/8 "2024-11-13T16:25:17Z")

</div>

I deleted it because I failed to notice you tagged this with vision, my brain defaulted to perspective. `event.source.buttonBG = 255,0,0` should work in vision, so something else is going on.
