Export Alarm Journal to CSV

Hello guy’s and girls,

i would appreciate some help with the system.alarm.queryJournal function in 7.7…

We have an alarm table and all the alarms have their priorities linked to them. When i export this table to CSV we use the following script:

get filters

start = event.source.parent.getComponent(‘Alarm Journal’).startDate
end = event.source.parent.getComponent(‘Alarm Journal’).endDate
selectedsource = event.source.parent.getComponent(‘Tree View 1’).MakeStringInstallations
actualdate = event.source.parent.Actualdatetime + " " + “alarmJournal”
priorities = [event.source.parent.Priorities]

export the journal to excel

journal = system.alarm.queryJournal(startDate=start, endDate=end, priority=priorities, displaypath=selectedsource).getDataset()
system.dataset.exportCSV(actualdate, 1, journal)

The priorities are the real problem here. They are combined using checkboxes so the user can select what priorities should be exported.
When i manually decline these ( i replace the “event.source.parent.Priorities” with “Low”,“High”) the script runs fine and i get a neat CSV file.
But when i want to get the variable from my custom parameter i get the error:
"caused by ClassCastException: Error trying to coerce ‘Low,Medium’ [String] to a class java.lang.Integer
"
No matter how i format the variables (with/without single/double quotes) i can’t get this to work.

Does anybody know what mistake i’m making here and/or have an example of an functioning script he/she would like to share with me??
*edit: typo

There isn’t quite enough information about the setup for me to recreate this, but my guess is that the line priorities = [event.source.parent.Priorities] is not returning “Low”,“High”, but instead returning ‘Low,High’. Since there is no alarm priority named “Low,High”, casting it to an enum is failing.

Try adding a debugging statement to print out the value of priorities. If it is a single string, try splitting it into a list using priorityList = priorities.split(',') and passing priorityList into system.alarm.queryJournal()

Dear Kathy,

thank you for your quick reply, unfortunately it did’t do the job…

Let me explain in a different way (without the troubles i ran into!)

I would like to have an export to CSV function (Button) on a page where we have an alarm journal. The user should be able to select the priority (severity) of the alarms that should be exported (e.g. “Low”,"Medium"etc) by checking a one or more checkboxes on that page (one checkbox for each priority).
After selecting the severities to be exported the user would then click a button to start the export (to CSV) of these alarms…

What would the script under the “Generate CSV” button look like…??

It looks to me Ignition is adding single quotes when i retrieve a variable from an custom parameter could this be adding to the issue at hand??

Hope to hear from you again!!
With kind regards!

Check boxes may be a bit clunky from a scripting standpoint – this forum thread has some tips on a more elegant way to get the info.

That said, here’s a quick and dirty script to get you going. It assumes 5 check boxes named Priority_Critical, Priority_High, etc. I’m sure the file name isn’t quite the format you want, but you can play around with that, as well as adding error checking to prevent someone from trying to save an empty list, etc.

The basic idea is that you need to get the user selection and make a list of strings from it to pass to system.alarm.queryJournal()

[code]import time

priorities = []
if event.source.parent.getComponent(‘Priority_Critical’).selected:
priorities.append(‘Critical’)
if event.source.parent.getComponent(‘Priority_High’).selected:
priorities.append(‘High’)
if event.source.parent.getComponent(‘Priority_Medium’).selected:
priorities.append(‘Medium’)
if event.source.parent.getComponent(‘Priority_Low’).selected:
priorities.append(‘Low’)
if event.source.parent.getComponent(‘Priority_Diagnostic’).selected:
priorities.append(‘Diagnostic’)

start = event.source.parent.getComponent(‘Alarm Journal’).startDate
end = event.source.parent.getComponent(‘Alarm Journal’).endDate
fileName = time.strftime("%Y%m%d") + “_” + “alarmJournal”

export the journal to excel

journal = system.alarm.queryJournal(startDate=start, endDate=end, priority=priorities).getDataset()
system.dataset.exportCSV(fileName, 1, journal)[/code]

Kathy!
You brought the cake AND the cherry on top!
If you weren’t on the other side of the world you would get hug right now!

Never crossed my mind to use the “append” statement for building a list…This solution is giving me new ideas about how to program some things we still need!

Lots of thanks!!

So glad I could help! :thumb_left:

How can I specify the alarm journal name? This seems to only work when the default alarm journal is configured.

Just change all occurrences of ‘Alarm Journal’ to a variable and set the variable to the name of your alarm journal component.

Hello Kathy,

May I know the way to write the script for getting the all priorities level of the alarm (Critical, High, Medium, Low)?
I really appreciate your response.
Thanks.