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()
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??
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’)
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!
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.