# system.alarm.queryStatus with expression

**URL:** <https://forum.inductiveautomation.com/t/system-alarm-querystatus-with-expression/18514>\
**Category:** Ignition\
**Created:** [June 18, 2018, 7:34pm UTC](https://forum.inductiveautomation.com/t/system-alarm-querystatus-with-expression/18514 "2018-06-18T19:34:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikenna.nwaogu](https://avatars.discourse-cdn.com/v4/letter/i/e274bd/32.png) [@ikenna.nwaogu](https://forum.inductiveautomation.com/u/ikenna.nwaogu)\
**Post date:** [June 18, 2018, 7:34pm UTC](https://forum.inductiveautomation.com/t/system-alarm-querystatus-with-expression/18514/1 "2018-06-18T19:34:39Z")

</div>

Can someone please help me with this. I am trying to bind this query to an integer custom property. I have spent 2 days on this trying to figure out why am getting errors. I wanted to filter through associated data.

I frist started with this  
toInt(runScript(“system.alarm.queryStatus(state=[‘ActiveUnacked’], includeSystem=False, all\_properties=[(‘Audience’,’=’,‘Mine’)])”

and  
runScript("len(system.alarm.queryStatus(state=[‘ActiveUnacked’], includeSystem=False, all\_properties=[(‘Audience’,’=’,‘Mine’)]))

got this error  
15:26:27.700 [AWT-EventQueue-2] ERROR com.inductiveautomation.factorypmi.designer.property.configurators.ExpressionConfigurator - Syntax Error on Token: ‘End of Expression’ (Line 0 , Char 0)

This works query runs as script but not as expression.

Also is there anyway to poll from a script? Thank You.

---

<div class="post-metadata">

**Author:** ![phillip.bow](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@phillip.bow](https://forum.inductiveautomation.com/u/phillip.bow)\
**Post date:** [June 18, 2018, 7:58pm UTC](https://forum.inductiveautomation.com/t/system-alarm-querystatus-with-expression/18514/2 "2018-06-18T19:58:20Z")

</div>

Your expression syntax isn’t quite right which is causing the syntax error(unmatched double quotes and unmatched parens).

This should work:

```auto
runScript("len(system.alarm.queryStatus(state=['ActiveUnacked'], includeSystem=False, all_properties=[('Audience','=','Mine')]))")

```

Do your arguments change in your calls to queryStatus? If you can move your queries in to a script like this it’ll simplify those expressions:

```auto
# project.alarmQueries
getUnackedAlarms(propName, val):
  return system.alarm.queryStatus(state=['ActiveUnacked'], includeSystem=False, all_properties=[(propName,'=',val)]

countUnackedAlarms(propName, val):
  return len(system.alarm.queryStatus(state=['ActiveUnacked'], includeSystem=False, all_properties=[(propName,'=',val)])

```

Then your expression would look like this, and you can adjust polling by changing the ‘0’ argument to your polling interval:

```auto
runScript("project.alarmQueries.getUnackedAlarms", 0, "Audience", "Mine")
runScript("project.alarmQueries.countUnackedAlarms", 0, "Audience", "Mine")

```

Another approach would be to set up a gateway event script on a timer that queries alarm status on your desired polling schedule, and writes the relevant info out to a tag that you can bind to from your UI.

---

<div class="post-metadata">

**Author:** ![ikenna.nwaogu](https://avatars.discourse-cdn.com/v4/letter/i/e274bd/32.png) [@ikenna.nwaogu](https://forum.inductiveautomation.com/u/ikenna.nwaogu)\
**Post date:** [June 18, 2018, 8:32pm UTC](https://forum.inductiveautomation.com/t/system-alarm-querystatus-with-expression/18514/3 "2018-06-18T20:32:35Z")

</div>

> [@phillip.bow](#):
>
> runScript("len(system.alarm.queryStatus(state=['ActiveUnacked'], includeSystem=False, all\_properties=[('Audience','=','Mine')]))")

Thanks a lot. I actually figured the syntax error. it also seem like you have to have at least 2 parameters for it the query to run. I will definitely keep the script in mind for future alarming needs. I know I have a bunch to come so I'll simplify it through this. Thanks again.
