Using client script to generate html export of a table

I have a table on a window that gets automatically refreshed every 5 minutes. every 30 minutes or so, I would like to export the table to html and overwrite the existing html that was previously generated. what is the best way to accomplish this?

You can add a timer component to the window that is set to run every 30 minutes. On the actionPerformed event you can put a script like this:data = event.source.parent.getComponent("Table") html = system.dataset.dataSetToHTML(1, data, "Production Report") filePath = "C:\\output\\results.html" system.file.writeFile(filePath, html)That will override the file every 30 minutes.

That doesnt seem to work for me, I get this error:

[code]Traceback (innermost last):

File “event:actionPerformed”, line 2, in ?

TypeError: dataSetToHTML(): 2nd arg can’t be coerced to com.inductiveautomation.ignition.common.Dataset

Ignition v7.2.11-beta1 (b209)
Java: Sun Microsystems Inc. 1.6.0_30
[/code]

this is the command I am currently using to export, but it asks me to save the file, I just want it to save automatically in a certain path. Any way I can tell this command which path to use and not to prompt me for the path?

event.source.parent.getComponent("Table").exportHTML("data.html", event.source.parent.getComponent('Path').text, 600)

Sorry, you need to get the table’s data property. Try this:data = event.source.parent.getComponent("Table").data html = system.dataset.dataSetToHTML(1, data, "Production Report") filePath = "C:\\output\\results.html" system.file.writeFile(filePath, html)

Almost, but not quite! It’s exporting all of the hidden columns whereas the function I am using above only exports visible columns. Any way to make it work like the other function and only show the visible columns?

Thanks

Ok, here you go:table = event.source.parent.getComponent("Table") html = table.getDataAsHTML(event.source.parent.getComponent('Path').text, 600) filePath = "C:\\output\\results.html" system.file.writeFile(filePath, html)

1 Like

thanks, that did it.