Filtering active alarms based on count

Hello, I was working on a project in which the alarm status table, I want to filter the active alarms based on the occurrence. For example, for a particular machine, when it goes into the alarm state, I want to show its 10 most recent alarms. Can anybody suggest what should I do?

I was able to filter the alarms by the display path, but I need suggestions on how to display recent active alarms.

If your trying to do that using the built in alarm table, I don’t believe you will be able to do it. I believe you will need to use a combination of system.alarm.queryStatus() and system.alarm.queryJournal(). Then you would put your results in a table or power table. The issue I see is that for system.alarm.queryJournal() you have to provide a date/time range for it to look at or it only looks at the previous 8 hours. It also assumes you have an alarm journal setup. I’m assuming your 10 most recent could be well outside of that range. I’m not sure how you would look for just the previous 10 without having a large range setup but that would slow down getting results and you could have to filter a lot out through a script.

The alarm Journal is stored in your database. With that you can use system.alarm.queryStatus() to get your active alarms and then do a standard query against your alarm journal table in your database to pull the recent alarms your looking for. Doing it that way you don’t have to worry about setting a time range since you can limit the number of results it returns. You would still need to script combining the results to insert into your table.

1 Like

Hello, I tried solving this thing with a different approach than you’ve suggested. I used a power table and applied a SQL Query:

SELECT TOP 10 * FROM (SELECT ROW_NUMBER() OVER (PARTITION BY eventid ORDER BY eventtime DESC) AS RN, * FROM alarm_events WHERE displaypath LIKE ('Station' +(CAST 1 AS VARCHAR(10)) + ' %')) alarms WHERE RN = 1 AND eventtype = 0 ORDER BY eventtime DESC

I want to know one thing though regarding the alarm status table. When I see the data in the power table I can see some items on retracing back in the main alarm status table which shows all the alarms are nowhere to be found.

So my question is that why I can’t see an alarm that would have cleared after been active from the alarm status table and still visible in the database table of alarm events.

The second question is a silly one, just like we can access the data from the database table, how we can access the data coming in the pre-build component of the alarm status table.

I’m not sure what you mean by “in the main alarm status table which shows all the alarms are nowhere to be found.”

I’m assuming it has to do with the next line. The alarm status table doesn’t look at the database table for events. It is fully internal to Ignition unlike the alarm journal table. The alarm journal table links to a journal profile. If you only have one journal in the gateway then it will always default to that one, otherwise you have to specify which one so it knows where to look for it. Even without the journal, the alarm table can show the last time an alarm has been cleared. I’m not sure how far back it will tell you though and I would assume it will only give you the last event so if it goes back into alarm, I wouldn’t expect it to show you when it cleared before that.

As far as I know you can’t access the data directly from the alarm status table but that is where the alarm script functions come in. system.alarm.queryStatus() can be used to return the same information.