I have a gateway script triggered on a tag (SMMain/TriggerReportProduction) that used to only send 1 email, but since upgrading to V8 from V7.9, I have started to receive 2. I started to see this issue with V8.02 and have since upgraded to V8.03.
Here is my script, I hope that someone will see my mistake.
I have added logging to make sure that the email IF statement is only being called once. Log info follow the script.
Thanks.
>
> logger = system.util.logger("TestTriggerReport")
> #logger.info("Info to log")
> #logger.error("Error to log")
> start_time = system.date.format(system.date.now(), "yyyy-MMM-dd HH-mm-ss")
> logger.info("Start Report at " + start_time)
>
> logger.info("Starting TestTriggerReport")
>
> report_time = system.date.format(system.date.now(), "yyyy-MMM-dd HH-mm")
> filename = "Production Summary " + report_time + ".pdf"
> #Publish report to PDF file
> pdf_settings = {"path":"C:\\Ignition Reports", "fileName":filename, "format":"pdf"}
> #Email PDF to distribution list
> email_settings = {"to":["gloweware@gmail.com"], "smtpServerName":"EmailServer", "from":"gloweware@gmail.com", "subject":"Production Report " + report_time, "attachmentName":filename}
>
>
> trigger_report = system.tag.read("[default]SMMAIN/TriggerReportProduction").value
> if trigger_report:
> #Executes and distributes the report to a PDF
> save_time = system.date.format(system.date.now(), "yyyy-MMM-dd HH-mm-ss")
> logger.info("Saving Report at " + save_time)
> system.report.executeAndDistribute(path="ProductionReport", project="Reports_V2", action="save", actionSettings=pdf_settings)
>
> trigger_email = trigger_report and system.tag.read("[default]SMMAIN/EmailReportProduction").value
> if trigger_email:
> # Executes and distributes the report to an email address.
> # FYI: The email server is set up on the gateway via the web interface
> email_time = system.date.format(system.date.now(), "yyyy-MMM-dd HH-mm-ss")
> logger.info("Sending Report at " + email_time)
> system.report.executeAndDistribute(path="ProductionReport", project="Reports_V2", action="email", actionSettings=email_settings)
>
> #Send a handshake back to SMMAIN in all cases
> system.tag.write("[default]SMMAIN/TriggerReportProductionHS",1)
>
> done_time = system.date.format(system.date.now(), "yyyy-MMM-dd HH-mm-ss")
> logger.info("Finished Report at " + done_time)
Log Info:
TestTriggerReport | 11Sep2019 06:32:10 | Finished Report at 2019-Sep-11 06-32-10 |
---|---|---|
TestTriggerReport | 11Sep2019 06:32:10 | Starting TestTriggerReport |
TestTriggerReport | 11Sep2019 06:32:10 | Start Report at 2019-Sep-11 06-32-10 |
TestTriggerReport | 11Sep2019 06:32:08 | Finished Report at 2019-Sep-11 06-32-08 |
TestTriggerReport | 11Sep2019 06:32:06 | Sending Report at 2019-Sep-11 06-32-06 |
TestTriggerReport | 11Sep2019 06:32:05 | Saving Report at 2019-Sep-11 06-32-05 |
TestTriggerReport | 11Sep2019 06:32:05 | Starting TestTriggerReport |
TestTriggerReport | 11Sep2019 06:32:05 | Start Report at 2019-Sep-11 06-32-05 |