system.net.sendEmail Sending Two Emails to One Address

I am using a gateway event script to evaluate if data was created in a SQL database. At the end of this script, an email is sent if any data was missed. The script is evaluating everything correctly, but it is sending me 2 emails each time instead of one.

currentDateTime = system.tag.read('[System]Gateway/CurrentDateTime').value
currentDateString = system.date.format(currentDateTime, 'MM/dd/yyyy')
activeUICs = system.db.runQuery("SELECT site_name, uic, site_active FROM ignition.expected_sites")
activeUICsCSV = system.dataset.toCSV(activeUICs, showHeaders = 0)
storageQuery = 'SELECT uic FROM ignition.datatable WHERE date = "' + currentDateString + '"'
dataStored = system.db.runQuery(storageQuery)
dataStoredCSV = system.dataset.toCSV(dataStored, showHeaders = 0)
counter = 0
sitesNotCaptured = "The Following Sites Were Not Able Capture Data Today:\n"
missingUICs = 0
for i in activeUICsCSV.split('\n'):
	UICCaptured = 0
	counter = counter + 1
	iSplit = i.split(',')
	dataStoredCounter = 0
	for i in dataStoredCSV.split('\n'):
		if "0" in iSplit[2]:
			UICCaptured = 1
			break
		dataStoredCounter = dataStoredCounter + 1
		if iSplit[1] == i:
			UICCaptured = 1
			break
		if dataStoredCounter == len(dataStoredCSV.split('\n')) - 1:
			break
	if counter == len(activeUICsCSV.split('\n')) - 1:
		break
	if UICCaptured == 0:
		sitesNotCaptured = sitesNotCaptured + iSplit[0].strip('"') + '\n'
		missingUICs = missingUICs + 1
recipients = ["myEmail@myCompany.com"]
emailBody = sitesNotCaptured
gateway = "smtp.gateway.example:25:tls"
source = "automated@email.com"
pw = "myPass"
system.net.sendEmail(smtp = gateway, fromAddr = source, subject="Data - Missing Sites", body=emailBody, html=0, to=recipients, username=source, password=pw)

Add a print statement right before you call system.net.sendEmail and see if it gets printed once or twice.

The print statements end up in the wrapper.log file, or on the logs page in the Ignition Gateway web interface if you use a logger: system.util.getLogger | Ignition User Manual

When I print the recipients I get an array with a single email address in it. When I run the script from the script console it only sends 1 email, but when I run it as a Scheduled Event at the gateway level it sends 2 emails. The script is exactly the same, I copied it out of the script console and pasted it in the Scheduled Events.

Ok, none of that answers my apparently implicit question: if you add the print statement I described does it print once or twice when the scheduled script runs?

I'm trying to figure out if this script is executing more often than you think, or if you defined it in some parent project that has multiple child projects, so it's actually executing in each child.

The last portion of this explains it, I am running it in a parent project and have multiple child projects. I was not aware that the parent project ran Gateway Event scripts for each child project.

As to implicitly answering your question, I was confused as to A) what you wanted me to print or B) what the purpose of this print was, so I assumed you were asking if it was printing the recipient address multiple times. I moved the script to a child project and it is working as intended.

Thank you for your time

It's not quite like this. They don't run in the parent project at all.

But each child project inherits it and it runs there.