Igntion 8.1.55
I have a script that works fine when run through a button or the script console, but when it is executed as a gateway event (tag change), it doesn't populate the data from the historian. The attachment only contains the time stamp, all other fields are blank.
Here is a short version of the script.
from org.python.core.util import StringUtil
import java.lang.Exception
strsDate = system.tag.readBlocking(["[default]Start_Date"])[0].value
streDate = system.tag.readBlocking(["[default]End_Date"])[0].value
strTime = system.tag.readBlocking(["[System]Gateway/CurrentDateTime"])[0].value
strReportDate = system.tag.readBlocking(["Reports/ReportDate"])[0].value
TagsPath = ["[]FIT-1506/EU","[]FIT-1506/Totalizer/Kscale""]
headers = ["t_stamp","FIT1506_GPM","FIT1506_KTotal"]
data = system.tag.queryTagHistory(TagsPath,startDate=strsDate,endDate=streDate, intervalMinutes=15, returnSize=96,aggregationMode="Average",returnFormat='Wide',columnNames=headers)
csv = system.dataset.toCSV(data)
strSubject = "%s DPE Export" %(strReportDate)
strBody = ""
objAttachment = StringUtil.toBytes(csv)
strFileName = "%s_DPE_Export.csv" %(strReportDate)
system.net.sendEmail(smtp=smtp_server, fromAddr=smtp_user, subject=strSubject, body=strBody, html=0, to=recipients, attachmentNames = [strFileName],attachmentData=[objAttachment],username=smtp_user,password=smtp_pwd)
filePath = "C:\myReports\%s DPE Export.csv" %(strReportDate)
system.file.writeFile(filePath, csv)