# Alarm Journal Query - Fastest Way to get Event Timestamps

**URL:** <https://forum.inductiveautomation.com/t/alarm-journal-query-fastest-way-to-get-event-timestamps/68983>\
**Category:** Ignition\
**Created:** [January 24, 2023, 11:05pm UTC](https://forum.inductiveautomation.com/t/alarm-journal-query-fastest-way-to-get-event-timestamps/68983 "2023-01-24T23:05:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![j.israelsen](https://avatars.discourse-cdn.com/v4/letter/j/ad7895/32.png) [@j.israelsen](https://forum.inductiveautomation.com/u/j.israelsen)\
**Post date:** [January 24, 2023, 11:05pm UTC](https://forum.inductiveautomation.com/t/alarm-journal-query-fastest-way-to-get-event-timestamps/68983/1 "2023-01-24T23:05:47Z")

</div>

I am trying to get historical alarm data. I'm doing it with the Alarm Journal Query (system.alarm.queryJournal) to avoid different syntaxes and compatibilities across varying databases. I am trying to get the Active, Acknowledged, and Cleared timestamps. However, these timestamps are spread across multiple events. I'm running into performance issues as I am trying to scale this up, for example:

1. Get all the UUIDs for the time range (at least 30 days, which is could be easily thousands of events)
2. Get a list of all the unique UUIDs (which is likely still thousands)
3. Find all the events that match a specific UUID (which is generally 3: active, acknowledge, clear)
4. Find all the timestamps from the events for my specific UUID
5. Loop back to Item #3 until we step through all of our UUIDs and get all of our information (once again easily need to loop thousands of times because of Item #2)

Is there an easier or more efficient way of doing this?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 25, 2023, 2:02am UTC](https://forum.inductiveautomation.com/t/alarm-journal-query-fastest-way-to-get-event-timestamps/68983/2 "2023-01-25T02:02:18Z")

</div>

Just add .getDataset() to the end of your query. This will reduce the alarm objects to a single and more managable dataset object that has the following seven columns: UUID, Qualified Path, Display Path, TimeStamp, State, Priority, and IsSystemEvent. From there, the unneeded columns could be removed, and the dataset could be sorted by UUID or EventTime.

Here is a code example:

```auto
endDate = system.date.now()
startDate = system.date.addDays(endDate, -30)
columnsOfInterest = ['EventId', 'EventTime', 'EventState']
dataset = system.alarm.queryJournal(startDate = startDate, endDate = endDate).getDataset()
filteredSet = system.dataset.filterColumns(dataset, columnsOfInterest)
sortedData = system.dataset.sort(filteredSet, 0, True)

```

Here is the result:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/5/052c858a81a3ab98b458eea9e9b7479cf72467a5.png)

With this approach, the event states come through as integers. If the string values are needed, they will have to be converted according to this table:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/a/5a0be775142657f7ba6bb1800a56ed448f981fcf.png)
