Hi
How can I trap this error which shows up when I close the save file window without saving file
I am using a button to generate a csv file - when i save the file there is no popup but if i cancel the file saving it gives me this popup
Troubleshooting scripts is difficult if you don’t share the script.
import csv
import datetime
# Obtain the java init date from the Input on the screen
datastart = event.source.parent.getComponent('Start Date').date
dataend =event.source.parent.getComponent('Start Date 1').date
#Calculate the number of hours in between the two dates
#Return size is the data points to be collected from starttime to endtime
Return_size=system.date.secondsBetween(datastart, dataend)/event.source.parent.getComponent('Dropdown_Datapoints').selectedValue
print(Return_size)
data = system.tag.queryTagHistory(paths = ["[edge]Engine1_rpm.value","[edge]Pump1_RPM.value","[edge]Pump1_strokes.value","[edge]Pressure_sensor_pump1.value","","[edge]FlowRatePump1.value","[edge]Pump1_flow_Total.value"],startDate=datastart, endDate=dataend, returnSize=Return_size, aggregationMode="Average", returnFormat='Wide')
csv = system.dataset.toCSV(data)
CustomerName = event.source.parent.getComponent('cstnm').text
JobNumber = event.source.parent.getComponent('Jobnumber').text
From=system.date.format(datastart, "yyyy-MM-dd-HH-mm-ss")
To=system.date.format(dataend, "yyyy-MM-dd-HH-mm-ss")
fnm = "PUMP1_DATA_"+From+"_to_"+To+".csv"
filename = system.file.saveFile(fnm)
system.file.writeFile(filename,csv)
Using the example in the manual, try this:
filename = system.file.saveFile(fnm)
if fileName is not None:
system.file.writeFile(filename,csv)
Working - just had to change the fileName to filename as fileName does not exist
1 Like
Sorry about that. I tend to use camel case in my code.
2 Likes
It looks like @JordanCClark already solved your problem, but generally speaking if you want to catch an error you use a try\except
clause. In your case, you’d have to do
import java.lang.NullPointerExecption
try:
# Your function call here
except NullPointerException, e:
# Log the error and handle gracefully to the user here