Retrieve data from database and save it as CVS file everyday at a fixed time

Greetings,

Our team is trying to retrieve data from the database and save it as a CVS file at a fixed timeslot (Let say every day1150pm) using Ignition. May I know anyone who tries to do this in Ignition through scripting? I look through the user manual and found out that the only gateway event script related to the timer is Timer Scripts but I not sure the timer scripts can be used to do this.

However, Ignition does have a function that enables us to save data in power table into CSV file
https://docs.inductiveautomation.com/display/DOC80/Exporting+and+Importing+a+CSV

Possible to combine these two functions to make what we wish for?

Hello,

If you want a script to be executed at a specific time every day, the best option for me, is to use an expression tag which should be a boolean set to True depending on your conditions. Then create a Tag Change Gateway Event Script and when your boolean becomes True, your script will execute.

For example, I created an expression tag I named trigger_export. Here is the expression used :
image

Then i created a Tag Change Gateway Event Script :

if newValue.value ==1 and initialChange==0: #If tag becomes True
	results = system.db.runQuery("SELECT * FROM example1 LIMIT 100")
	results = system.dataset.toDataSet(results)
	csv = system.dataset.toCSV(dataset = results, showHeaders = True, forExport = False)
	filePath = "C:\\output\\results.csv"
	system.file.writeFile(filePath, csv)

Check out this link for more info about the function to export to csv : system.dataset.toCSV - Ignition User Manual 8.0 - Ignition Documentation

2 Likes

You are right. I can try on this. How could I never think of this method before. I will have a try on this method. Thanks for the idea. =)