Schedule Report Run Scrip Save Data to CSV

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!

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

Can you try adding [default] to the tagpaths?

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…

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