# Email table data in 7.7.4

**URL:** <https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058>\
**Category:** Ignition\
**Created:** [January 18, 2016, 5:03pm UTC](https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058 "2016-01-18T17:03:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [January 18, 2016, 5:03pm UTC](https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058/1 "2016-01-18T17:03:01Z")

</div>

Hi guys, not sure when the IT department if going to update to 7.8 but till then I suppose I can try this the hard way. So as the subject of the email says, I want to send an automated email at 7:02 am 15:02 pm and  
23:02 pm and each email is going to include multiple query results, I do have a Boolean tag that comes on at those 3 times so would it be better just use the

```auto
system.net.sendEmail(smtp, fromAddr, subject, body, html, to, attachmentNames, attachmentData, timeout, username, password, priority)
```

in the check box component scripting and when the bits come on I send that email or would it better doing it under the Gateway even script?

---

<div class="post-metadata">

**Author:** ![weertske](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/weertske/32/3353_2.png) [@weertske](https://forum.inductiveautomation.com/u/weertske)\
**Post date:** [January 21, 2016, 10:45pm UTC](https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058/2 "2016-01-21T22:45:52Z")

</div>

I use a gateway tag change event script.

This one runs twice a day (\*\*\* is redacted info):

[code]trigger = system.tag.read("[]NTU Report Trigger")

if trigger.value == 1:  
results = system.db.runQuery(“SELECT Top 3 CAST(Pit\_A\_Turb AS DECIMAL(18,1)) AS ‘Pit A’, CAST(DAF\_A\_Turb AS DECIMAL(18,2)) AS ‘DAF A’, CAST(DAF\_B\_Turb AS DECIMAL(18,2)) AS ‘DAF B’, CAST(SF\_A\_Turb AS DECIMAL(18,2)) AS ‘SF A’, CAST(SF\_B\_Turb AS DECIMAL(18,2)) AS ‘SF B’, CAST(SF\_C\_Turb AS DECIMAL(18,2)) AS ‘SF C’, CAST(SF\_D\_Turb AS DECIMAL(18,2)) AS ‘SF D’, CAST(SF\_E\_Turb AS DECIMAL(18,2)) AS ‘SF E’, CAST(Surge\_Tank\_Turb AS DECIMAL(18,2)) AS ‘Surge’, CAST(Pipeline\_Turb AS DECIMAL(18,2)) AS ‘Pipeline’, t\_stamp AS ‘time stamp’, username FROM Frac\_Office\_Data WHERE t\_stamp IS NOT NULL ORDER BY t\_stamp DESC”)  
results = system.dataset.toDataSet(results)  
html = system.dataset.dataSetToHTML(1, results, “\*\*\* NTU Data”)  
bodyhtml = “

# \*\*\* NTU Data
”+ html  
body = bodyhtml  
recipients = ["\*\*\*@\*\*\*.com", “\*\*\*@\*\*\*.com”, “\*\*\*@\*\*\*.com”]  
system.net.sendEmail(smtp="\*\*\*.local", fromAddr=“ignition@\*\*\*.com”, subject="\*\*\* NTU Data", body=body, html=1, to=recipients)  
[/code]

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [January 21, 2016, 10:57pm UTC](https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058/3 "2016-01-21T22:57:35Z")

</div>

If at all possible, it’s nice to run these kind of things (that do something at some tag change or some time) on the Gateway rather than in a component script. If it’s in a component script, you need to make sure that you always have one client up with that component’s window open, but you have to deal with making sure you don’t duplicate things if two or more clients are up with that window open. In the Gateway, you won’t have duplication issues and your Gateway should (ideally) always be up.

When (not if 🙂 ) you upgrade to 7.8, you can put all that into a report that gets emailed. These concerns with making sure clients are open at the right time were a big motivator behind our decision to move report execution to the Gateway.

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [March 12, 2018, 3:15pm UTC](https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058/4 "2018-03-12T15:15:42Z")

</div>

@weertske  
Never got to thank you for your response! I did use this but we ended up updating to 7.8 and I started playing with the reporting module and boy I never looked back! lol

@KathyApplebaum  
Thanks for the suggestion, I do try to use the gateway even script for stuff like this and it has helped a lot.  
I’m using reporting module and it’s amazing and keeps getting better, I have one question tho, what would be the best approach if I wanted to manually trigger a report to be sent out? the simplest example is a memory BOOL tag that gets triggered using a button by user, now is there a way I can trigger the report execution to that tag?

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [March 12, 2018, 3:48pm UTC](https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058/5 "2018-03-12T15:48:22Z")

</div>

> [@Mr.K001](#):
>
> what would be the best approach if I wanted to manually trigger a report to be sent out? the simplest example is a memory BOOL tag that gets triggered using a button by user, now is there a way I can trigger the report execution to that tag?

I'd use a tag event script -- when the value changes to 1, call system.report.executeAndDistribute().

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 12, 2018, 3:51pm UTC](https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058/6 "2018-03-12T15:51:55Z")

</div>

> [@KathyApplebaum](#):
>
> I'd use a tag event script -- when the value changes to 1, call system.report.executeAndDistribute().

If it's coming from a button press in the first place, there's no reason the button's actionPerformed event can't call executeAndDistribute() itself, cutting out the tag in the middle.

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [March 12, 2018, 4:03pm UTC](https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058/7 "2018-03-12T16:03:03Z")

</div>

Perhaps I should have looked at the scripting section of the manual first 😜  
One other question, so my reports are mainly email and I have added bunch of email addresses, If I manually execute and distribute the report, will it by default execute the email action I have in there with all the addresses or do I still have to specify all the addresses in my script? I suppose if it doesn’t I can create user groups and put those addresses in there and just use that in the script.  
I assume if I have two different email actions ( say one to management, one to supervisors with different timing) there is no way to specify if I want to execute the first email action or second one correct?  
I’m just asking these because they just popped in my head, I definitely can think of ways to get around this and get the results I want, I just figured I pick your smart brains first 🤓

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [March 12, 2018, 4:35pm UTC](https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058/8 "2018-03-12T16:35:31Z")

</div>

The scheduled actions are completely separate from the script actions.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [March 12, 2018, 4:36pm UTC](https://forum.inductiveautomation.com/t/email-table-data-in-7-7-4/11058/9 "2018-03-12T16:36:23Z")

</div>

> [@pturmel](#):
>
> If it's coming from a button press in the first place, there's no reason the button's actionPerformed event can't call executeAndDistribute() itself, cutting out the tag in the middle.

Duh, of course. That's what I get for looking at the forum before sufficient caffeine intake. 😳
