CSV Export Script Only Working on Specific Server

Hi All,

I currently have a script attached to a button that exports a .CSV file to a folder in the C:/ drive.
We have 2 servers - an Engineering Server and an Ignition Server.
It was discovered that when you are on the Engineering Server and connect to the Ignition Server, exporting the .CSV will save on the Ignition Server. Is there a way to export the .CSV on the server you are currently on?

Here is the script in question:

def runAction(self, event):

reportName = 'InvMonthlyPerformance'
savePath = 'C:\ReportFiles'
reportData = self.view.custom.inverterData
reportData = system.dataset.toPyDataSet(reportData)
year = str(self.view.custom.year)

### Add leading zero to month when necessary
if len(str(self.view.custom.month)) == 1:
	month = '0' + str(self.view.custom.month)
else:
	month = str(self.view.custom.month)

attachmentName = reportName+"_"+year+month
savePath = savePath+'/'+attachmentName

historicalCSV = system.dataset.toCSV(reportData)
system.file.writeFile(savePath, historicalCSV)
self.props.style.classes = 'Components/Buttons/Light'
self.getSibling("fileLocationTxt").meta.visible = True

When you say 'connect' do you mean with a designer or a perspective session? Perspective actions/scripts run on the gateway. If you are connected to your production gateway then the script will run there, it does not matter where you connect from.

1 Like

That would be considered malware. Malware very much wants to trick browsers into placing information onto victims systems. So browsers require user intervention to accept a download, and to direct a download to anywhere other than a default folder. system.perspective.download() is the only tool available to your.

I was able to download the file using this, however it seems to export as a .txt and not as a .csv.
Part of the input parameters is [contenttype] which I've left blank. I couldn't find an extensive list of possible inputs, is there something I should be using for .csv?

In the above code, I do have historicalCSV = system.dataset.toCSV(reportData), but trying to download this variable gives me a .txt

text/csv would be the appropriate content type.

Thank you for the quick reply. For some reason this hasn't been working. Here's what I've tried:

This does not export anything

system.perspective.download(attachmentName,reportData,csv)

This does not export anything

historicalCSV = system.dataset.toCSV(reportData)
system.perspective.download(attachmentName,historicalCSV,csv)

This exports a text

historicalCSV = system.dataset.toCSV(reportData)
system.perspective.download(attachmentName,historicalCSV)

What is csv in this line of code? If it isn't a variable containing the string "text/csv", it cannot possibly work. (You likely have errors in your gateway log.)

Thank you, I forgot to make this a string. It works now!