# Perspective Alarm Query

**URL:** <https://forum.inductiveautomation.com/t/perspective-alarm-query/61931>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 15, 2022, 5:03am UTC](https://forum.inductiveautomation.com/t/perspective-alarm-query/61931 "2022-07-15T05:03:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Smith](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@John\_Smith](https://forum.inductiveautomation.com/u/John_Smith)\
**Post date:** [July 15, 2022, 5:03am UTC](https://forum.inductiveautomation.com/t/perspective-alarm-query/61931/1 "2022-07-15T05:03:06Z")

</div>

Hoping someone can point me in the right direction.

I have tags that are sorted in folders as follows:

- Machine A
- Machine B
- Machine C

In my perspective application, I have a MenuTree component with menu’s as per above strucure. i.e.,

- Machine A
- Machine B
- Machine C

My question is as follows:  
a. How would I run a query on each menu item to change the text to red if there is any alarm in the tag folder?  
b. How would I run a query on each menu item to blink the text if there is any unack alarm in the tag folder?

Is there a better way to achieve the above?

Any help is appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![craigb](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@craigb](https://forum.inductiveautomation.com/u/craigb)\
**Post date:** [July 15, 2022, 7:46am UTC](https://forum.inductiveautomation.com/t/perspective-alarm-query/61931/2 "2022-07-15T07:46:26Z")

</div>

Edited to say I wrote all the below when there is a easier way. The menu A text color can have a expression binding…

```auto
if ({[default]MachineA/MATagAlarm}=1, "#CC4828", "#00FF00")

```

…

I had a go at this one for changing text color…

In the folder for Machine ‘A’ I created a expression tag with the expression below. Extend it if you have more tags. I made the datatype INT so it gives a 0 or 1 if any of the tags are true.

```auto
{[.]MAtagA} || {[.]MAtagB} || {[.]MAtagC} = true

```

You might want to drill down into the is alarm active value depending on how you have things set up.

Then on the Machine A menu I created 2 custom properties. The value binds to the expression tag above so goes 1 or 0 depending on state.

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

On the value property I added a change script.

```auto
	value = self.custom.value
	
	if value == 1:
		self.custom.color = '#CC4828'
			
	else: 
		value == 0
		self.custom.color = '#F93E10'

```

You can change the hex value to what color you want.

This then writes the hex code to the color custom property.

Then on the textstyle color property I bound that to the color custom property.

In the change script you could directly address the text style color but I like to keep things separate so i can see what’s going on and test. Personal preference I guess. But it would be something like…

```auto
	value = self.custom.value
	
	if value == 1:
		self.props.textStyle.color = '#CC4828'
			
	else: 
		value == 0
		self.props.textStyle.color = '#00FF00'

```

I hope that helps, or at least gets you started.

This is the end result that will need tailored to fit your application…

Alarm;

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

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

No Alarm;

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

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/8/6813b4ce061d4c828998e1c48291343f693a73c3.png)

---

<div class="post-metadata">

**Author:** ![John\_Smith](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@John\_Smith](https://forum.inductiveautomation.com/u/John_Smith)\
**Post date:** [August 3, 2022, 6:20am UTC](https://forum.inductiveautomation.com/t/perspective-alarm-query/61931/3 "2022-08-03T06:20:04Z")

</div>

Thank you so much @craigb for the detailed response. Your solution makes absolute sense when the tags are known in each folder. How can I detect an alarm in a folder if the tags are variable. i.e. in your expression you explicitly mention tags a to c. What if I add a tag d into the folder, I would have to update the expression, there could potentially be 100’s of tags in a folder.

Do you know of a script/expression to detect an alarm in a folder, without having to hardcode each tag?

Many thanks

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 3, 2022, 8:55am UTC](https://forum.inductiveautomation.com/t/perspective-alarm-query/61931/4 "2022-08-03T08:55:06Z")

</div>

Be very careful calling `system.alarm.queryStatus` as it will cause performance issues the more you call it and it **will not scale** , but you can use this function to query active alarms. I suggest calling this once periodically from a gateway scope such as from a tag using runScript and store the result into a module variable. You can then process the module variable to summarise the alarms for any folder level. Keep in mind you’ll need to do this all within the same scope eg all within tags

---

<div class="post-metadata">

**Author:** ![deon.korb](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@deon.korb](https://forum.inductiveautomation.com/u/deon.korb)\
**Post date:** [August 3, 2022, 9:08am UTC](https://forum.inductiveautomation.com/t/perspective-alarm-query/61931/5 "2022-08-03T09:08:23Z")

</div>

I think many have a similar requirement and hence I have requested some form of aggregation.

[Tag Alarm Aggregation | Voters | Inductive Automation (canny.io)](https://inductiveautomation.canny.io/ignition-features-and-ideas/p/tag-alarm-aggregation)

I see it is under review. Maybe a few more votes can speed matters along
