# Schedule Report Run Scrip Save Data to CSV

**URL:** <https://forum.inductiveautomation.com/t/schedule-report-run-scrip-save-data-to-csv/24574>\
**Category:** Ignition\
**Created:** [May 1, 2019, 11:32pm UTC](https://forum.inductiveautomation.com/t/schedule-report-run-scrip-save-data-to-csv/24574 "2019-05-01T23:32:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [May 1, 2019, 11:32pm UTC](https://forum.inductiveautomation.com/t/schedule-report-run-scrip-save-data-to-csv/24574/1 "2019-05-01T23:32:13Z")

</div>

Hi Guys,

I would like to save all the data that was used to generate a report to a CSV file when my report is scheduled to run. If I run the following script on a button on a window with the Report Viewer I get the CSV file as expected.

> startTimestamp = project.myFuncs.startOfLastMonth()  
> endTimestamp = project.myFuncs.endOfLastMonth()  
> data = system.tag.queryTagHistory(paths = ['Tag1Path', 'Tag2Path', 'Tag3Path'], startDate = startTimestamp, endDate = endTimestamp, returnSize=0, aggregationMode="MinMax", columnNames = ['Timestamp', 'Chamber 1 Temperature (F)', 'Chamber 2 Temperature (F)', 'Running'])  
> dataCSV = system.dataset.toCSV(data)  
> system.file.writeFile(savePath + backslash + folderName + backslash + "Data.csv", dataCSV)

When I try to run the same code in Report -\> Schedule -\> Run Script, the CSV file just has the column names with no actual data.

Any assistance would be very much appreciated!

---

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [May 2, 2019, 9:23pm UTC](https://forum.inductiveautomation.com/t/schedule-report-run-scrip-save-data-to-csv/24574/2 "2019-05-02T21:23:59Z")

</div>

I was thinking that since scheduled reports run on the gateway, that I needed to use shared rather than project scripts. I did this and changed my scheduled script to:

> startTimestamp = shared.myFuncs.startOfLastMonth()  
> endTimestamp = shared.myFuncs.endOfLastMonth()  
> data = system.tag.queryTagHistory(paths = [‘Tag1Path’, ‘Tag2Path’, ‘Tag3Path’, 'Tag4Path'], startDate = startTimestamp, endDate = endTimestamp, returnSize=0, aggregationMode=“MinMax”, columnNames = [‘Timestamp’, ‘Chamber 1 Temperature (F)’, ‘Chamber 2 Temperature (F)’, ‘Running1’, 'Running2'])  
> dataCSV = system.dataset.toCSV(data)  
> system.file.writeFile(savePath + backslash + folderName + backslash + “Data.csv”, dataCSV)

But I am still only getting the column headers in the CSV file...

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [May 2, 2019, 9:43pm UTC](https://forum.inductiveautomation.com/t/schedule-report-run-scrip-save-data-to-csv/24574/3 "2019-05-02T21:43:07Z")

</div>

Can you try adding [default] to the tagpaths?

---

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [May 2, 2019, 9:49pm UTC](https://forum.inductiveautomation.com/t/schedule-report-run-scrip-save-data-to-csv/24574/4 "2019-05-02T21:49:34Z")

</div>

To the beginning? I right clicked on the tags in the Tag Browser and clicked ‘Copy Tag Path’ and pasted into my script. This did not include [default] anywhere. I will try but the fact that this works on the client window and not on the schedule report makes me think there is something else going on…

---

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [May 2, 2019, 9:59pm UTC](https://forum.inductiveautomation.com/t/schedule-report-run-scrip-save-data-to-csv/24574/5 "2019-05-02T21:59:13Z")

</div>

Nope you were right, I guess you need to specify the tag provider for scheduled report scripts - thanks jpark!
