Custom Method from Gateway Script V7.7

I want to save the data from Easy Chart using a timed Gateway Script once a day.
I’ve written a custom method on the Easy Chart;

def SaveData(self):
self: A reference to the component instance this method is invoked on. This argument
is automatic and should not be specified when invoking this method.
# data = event.source.parent.getComponent(‘chrt01’)
# convert to csv
CSVdata = system.dataset.toCSV(data)
# write file
system.file.writeFile(“C:\adata\data.csv”, CSVdata)

I’ve tried calling the method from the Gateway, but everything I’ve tried results in an error and I cannot call the method.
I had hoped to invoke the method by setting a memory tag, but I can’t bind the method to a tag.
Or a way to call the built in method would be good.
Any help greatly appreciated.
Peter Murray.

The Easy Chart does not exist in the Gateway. It only exists in the Designer and in Clients. You will have to find another way.

Perhaps you can write a Gateway Script that uses the system.tag.queryTagHistory function to get the same or similar data.

Thanks for the reply Nick.
I’ve tried using ‘queryTagHistory’ which I do not know if that works just yet because I’ve hit another snag.
In trying to get the system date, I’m using V7.7, I get;

Traceback (most recent call last):
File “<TimerScript:LamaBevs/GetChartData @120,000ms >”, line 1, in
NameError: name ‘dateArithmetic’ is not defined

It is the same for the ‘now()’ function.
The* functions do not appear to be available in V7.7.
Do I need to declare a library to use these functions?

They aren’t available in v7.7 (or v7.8, IIRC). You should use the corresponding features of java.util.Calendar.

I see.
I’ve also noticed some other system functions are not available

Traceback (most recent call last):
File “<TimerScript:LamaBevs/newone @120,000ms >”, line 1, in
File “module:project.ProjScript”, line 5, in PetesProjFunction
AttributeError: ‘com.inductiveautomation.ignition.common.script.Scr’ object has no attribute ‘gui’

Traceback (most recent call last):
File “<TimerScript:LamaBevs/newone @120,000ms >”, line 1, in
File “module:project.ProjScript”, line 4, in PetesProjFunction
AttributeError: ‘com.inductiveautomation.ignition.common.script.Scr’ object has no attribute 'dataSet

I’ve run out of ideas with this.
I want to export one days worth of tag data to a CSV file for a customers auditing requirements.

Are there any suggestions for how I might go about this?

I’ve created shared scripts at both global and project levels which call the system.dataset.* and system.tag.* methods as outlined in the V7.7 manual, but I get the results shown above each time.
I’ve also tried using a custom method attached to an Easy Chart which I tried to call from a Gateway Event Script, but that did not work either, see previous posts.

Thank you to all who have assisted thus far.

That one’s just a typo.

Ok I’m back.
No worries, I got that typo, my mistake.
I have a project script which I can invoke using a button on the easy chart page and that returns a file with the header information and all the data.
The object is to have a Gateway Timed Event run the script once per day. When I invoke the script using the time event, I get a file with only the header information and no data.
What do I need to do to sort that one out?

You’ll have to show more code, but I suspect that you are trying to reference some GUI component or other. GUI components don’t exist and cannot exist in Gateway scope. Your timed gateway script has to construct all relevant filter conditions internally, or from items in gateway scope (like tags, via*), then retrieve data with the system.tag.*history* functions.

Here is ‘project.ProjScript’

def PetesProjFunction():
from java.util import Calendar
from java.util import Date
from java.text import SimpleDateFormat

now = Date()
datetimeStr = now.toString()
format = SimpleDateFormat("yyyyMMddHHmmss")
strFileName = "c:\\pete\\data\\CitrusData" + format.format(now) + ".csv"

c = Calendar.getInstance()
c.add(Calendar.DAY_OF_MONTH, -1)
newDate = c.getTime()

peteDataSet = system.tag.queryTagHistory(paths=['Process_PLC/Citrus/TT33_CitrusHotWater'], startDate=newDate, endDate=now, returnSize=-1, aggregationMode="MinMax", returnFormat='Wide')
csv = system.dataset.toCSV(peteDataSet, True, False)
system.file.writeFile(strFileName, csv)

The above function is called using the following Gateway Event Script.

The following picture shows the script attached to a button on a page I use to test the function.

When using the Script Playground or the button on a page, I get a file with the header and all trend data.
When the function is called by the Gateway Event Script, I get a file with only the header and no trend data.

Try changing your tag paths to include your historical tag provider name, as shown in the comments to the online documentation for system.tag.queryTagHistory().

Marvellous, thanks for that, that works with both the page button and the global timed event.
I changed the tag query function to include the Tag History provider;

peteDataSet = system.tag.queryTagHistory(paths=[’[LamaBevs]Process_PLC/Citrus/TT33_CitrusHotWater’], startDate=newDate, endDate=now, returnSize=-1, aggregationMode=“MinMax”, returnFormat=‘Wide’)