# Gateway Event Script sending two emails \[Solved\]

**URL:** <https://forum.inductiveautomation.com/t/gateway-event-script-sending-two-emails-solved/26847>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [July 24, 2019, 7:26pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sending-two-emails-solved/26847 "2019-07-24T19:26:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![yehet73190](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yehet73190/32/68157_2.png) [@yehet73190](https://forum.inductiveautomation.com/u/yehet73190)\
**Post date:** [July 24, 2019, 7:26pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sending-two-emails-solved/26847/1 "2019-07-24T19:26:55Z")

</div>

In regards to this post

> [@How to call report from gateway event script \[SOLVED\]](http://forum.inductiveautomation.com/t/how-to-call-report-from-gateway-event-script-solved/26823/3):
>
> awesome it worked! thank you! i used [system.report.executeAndDistribute()](https://docs.inductiveautomation.com/display/DOC80/system.report.executeAndDistribute)

The gateway script is working but it's sending me two emails instead of one. I mean, I only have one instance of executeAndDistribute but when I trigger it (to when the tag is = 1) its sending me two emails. Anything else I should check to make sure it only sends one email?

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [July 25, 2019, 11:08am UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sending-two-emails-solved/26847/2 "2019-07-25T11:08:41Z")

</div>

Its a shot in the dark, but any chance the report has a scheduled event configured in it? Also I would double check that the your tag change script specifically confirms the value is 1 otherwise it may trigger going high or low.

You could also try putting a logger into your script to confirm it only is executing once there.

---

<div class="post-metadata">

**Author:** ![yehet73190](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yehet73190/32/68157_2.png) [@yehet73190](https://forum.inductiveautomation.com/u/yehet73190)\
**Post date:** [July 25, 2019, 3:57pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sending-two-emails-solved/26847/3 "2019-07-25T15:57:43Z")

</div>

no it doesn’t have a scheduled event configured ☹

how can i put a logger on my script?

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [July 25, 2019, 4:08pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sending-two-emails-solved/26847/4 "2019-07-25T16:08:55Z")

</div>

```auto
     log=system.util.getLogger("Logger Name")
     log.warn("Message goes here")

```

Something like this should work. I use these temporarily to mark conditions in the system quite a bit during debug.

---

<div class="post-metadata">

**Author:** ![yehet73190](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yehet73190/32/68157_2.png) [@yehet73190](https://forum.inductiveautomation.com/u/yehet73190)\
**Post date:** [July 25, 2019, 4:12pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sending-two-emails-solved/26847/5 "2019-07-25T16:12:46Z")

</div>

oh cool brb, i’m gonna try that and see what goes on

---

<div class="post-metadata">

**Author:** ![yehet73190](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yehet73190/32/68157_2.png) [@yehet73190](https://forum.inductiveautomation.com/u/yehet73190)\
**Post date:** [July 25, 2019, 7:08pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sending-two-emails-solved/26847/6 "2019-07-25T19:08:27Z")

</div>

currently this is my code

```auto
exeRep = system.tag.read("[edge-ksvsclient_edge]ExecuteReport").value

if exeRep == 1:
	#code for system.report.executeAndDistribute
	system.tag.write("[edge-ksvsclient_edge]ExecuteReport", 0)
	log=system.util.getLogger("executeReport")
	log.warn("%s"%exeRep)
	
else:
	log=system.util.getLogger("executeReport")
	log.error("Failed")

```

I think the reason why its sending two emails is because of the tag write

> system.tag.write("[edge-ksvsclient\_edge]ExecuteReport", 0)

What im trying to do is when the user clicks on a button from the edge client it writes 1 to the tag "ExecuteReport" and from our central server it will send the report and then I want to reset the tag back to 0. This part works - I am getting the email and the tag is writing back to 0. But what I don't understand is why the tag write would cause the email to be sent twice? Any suggestions on the workaround for this that I could try? I tried putting the tag write outside the if condition but that didn't work out as well.

---

<div class="post-metadata">

**Author:** ![yehet73190](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/yehet73190/32/68157_2.png) [@yehet73190](https://forum.inductiveautomation.com/u/yehet73190)\
**Post date:** [July 25, 2019, 7:49pm UTC](https://forum.inductiveautomation.com/t/gateway-event-script-sending-two-emails-solved/26847/7 "2019-07-25T19:49:45Z")

</div>

i was able to make this work instead of

> `if exeRep == 1:`

I used

> if newValue.value:

yey
