# Gateway Event Script "system.dataset.toCSV"

**URL:** <https://forum.inductiveautomation.com/t/gateway-event-script-system-dataset-tocsv/117435>\
**Category:** Ignition\
**Tags:** vision, ignition81\
**Created:** [October 12, 2026, 8:29pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-system-dataset-tocsv/117435 "2026-10-12T20:29:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliom](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@juliom](https://forum.inductiveautomation.com/u/juliom)\
**Post date:** [October 12, 2026, 8:29pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-system-dataset-tocsv/117435/1 "2026-10-12T20:29:02Z")

</div>

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.

```python
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)

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 12, 2026, 8:32pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-system-dataset-tocsv/117435/2 "2026-10-12T20:32:36Z")

</div>

Can you post a more exact reproduction of your script?  
It's hard to confirm whether the issues with it are typos or real.

For instance,

> [@juliom](#):
>
> `TagsPath = ["[]FIT-1506/EU","[]FIT-1506/Totalizer/Kscale""]`

Is there actually a tag provider name, or do your literal tag paths include `[]` as the provider name?

> [@juliom](#):
>
> `strReportDate = system.tag.readBlocking(["Reports/ReportDate"])[0].value`

You're also missing a provider name here.

---

<div class="post-metadata">

**Author:** ![juliom](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@juliom](https://forum.inductiveautomation.com/u/juliom)\
**Post date:** [October 12, 2026, 9:40pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-system-dataset-tocsv/117435/3 "2026-10-12T21:40:41Z")

</div>

Thank you,

by adding the **tag provider name** the gateway event script works, still don't understand why it would work from a button but not the gateway event script. In previous version of igntion using `[]` it knew to use the default provider.

Once again thank you, tech support still working on the issue.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 12, 2026, 10:24pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-system-dataset-tocsv/117435/4 "2026-10-12T22:24:38Z")

</div>

Tag event scripts (e.g. `valueChanged`) run outside of any project and thus require explicit qualification of various things.

> **[Tag Paths | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.3/platform/tags/tag-paths)**
>
> Tags and their properties can be referenced by a string-based path in many areas of Ignition, such as expressions and scripts. Each tag has a unique absolute path and often has many equivalent relative paths when referenced from other tags. In most...

Distinct from tag change scripts, which run on the gateway but within the "scope" of a single project:

> **[Tag Change Script Interface​ - Gateway Event Scripts | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.3/platform/scripting/scripting-in-ignition/gateway-event-scripts#tag-change-script-interface)**
>
> Gateway Event Scripts are scripts that run directly on the Gateway. They are useful because they always run, regardless if any Sessions or Clients are open. They also provide a guaranteed way to make sure only a single execution of a particular...

In your use case, `[~]` should work, to refer to "the provider I'm currently in".
