system.alarm.queryStatus with expression

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.

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

This should work:

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:

# 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:

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.

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.