# CSV Export Script Only Working on Specific Server

**URL:** <https://forum.inductiveautomation.com/t/csv-export-script-only-working-on-specific-server/88950>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [April 16, 2024, 11:04pm UTC](https://forum.inductiveautomation.com/t/csv-export-script-only-working-on-specific-server/88950 "2024-04-16T23:04:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![IcedMocha12](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@IcedMocha12](https://forum.inductiveautomation.com/u/IcedMocha12)\
**Post date:** [April 16, 2024, 11:04pm UTC](https://forum.inductiveautomation.com/t/csv-export-script-only-working-on-specific-server/88950/1 "2024-04-16T23:04:09Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [April 16, 2024, 11:08pm UTC](https://forum.inductiveautomation.com/t/csv-export-script-only-working-on-specific-server/88950/2 "2024-04-16T23:08:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 17, 2024, 12:28am UTC](https://forum.inductiveautomation.com/t/csv-export-script-only-working-on-specific-server/88950/3 "2024-04-17T00:28:35Z")

</div>

> [@IcedMocha12](#):
>
> server you are currently on?

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.

---

<div class="post-metadata">

**Author:** ![IcedMocha12](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@IcedMocha12](https://forum.inductiveautomation.com/u/IcedMocha12)\
**Post date:** [April 17, 2024, 3:42pm UTC](https://forum.inductiveautomation.com/t/csv-export-script-only-working-on-specific-server/88950/4 "2024-04-17T15:42:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 17, 2024, 3:46pm UTC](https://forum.inductiveautomation.com/t/csv-export-script-only-working-on-specific-server/88950/5 "2024-04-17T15:46:40Z")

</div>

`text/csv` would be the appropriate content type.

---

<div class="post-metadata">

**Author:** ![IcedMocha12](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@IcedMocha12](https://forum.inductiveautomation.com/u/IcedMocha12)\
**Post date:** [April 17, 2024, 3:54pm UTC](https://forum.inductiveautomation.com/t/csv-export-script-only-working-on-specific-server/88950/6 "2024-04-17T15:54:27Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 17, 2024, 3:58pm UTC](https://forum.inductiveautomation.com/t/csv-export-script-only-working-on-specific-server/88950/7 "2024-04-17T15:58:53Z")

</div>

> [@IcedMocha12](#):
>
> system.perspective.download(attachmentName,historicalCSV,csv)

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.)

---

<div class="post-metadata">

**Author:** ![IcedMocha12](https://avatars.discourse-cdn.com/v4/letter/i/82dd89/32.png) [@IcedMocha12](https://forum.inductiveautomation.com/u/IcedMocha12)\
**Post date:** [April 17, 2024, 4:04pm UTC](https://forum.inductiveautomation.com/t/csv-export-script-only-working-on-specific-server/88950/8 "2024-04-17T16:04:57Z")

</div>

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