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
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?
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]
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.
@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?
I'd use a tag event script -- when the value changes to 1, call system.report.executeAndDistribute().
1 Like
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.
2 Likes
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
The scheduled actions are completely separate from the script actions.
Duh, of course. That's what I get for looking at the forum before sufficient caffeine intake.