Sending multiple emails based on table value

I have created a database (called Tracker) that looks like this:
image

This is used to keep tracking of service calls as well as their associated reports.

The technician has 1 day to turn in their report, before they receive an email reminder for them to turn it in. The email action is performed when a button is selected. The following is my code for this:

	table = self.getSibling("serviceCallTracker_Table")
	data = self.getSibling("serviceCallTracker_Table").custom.data	
	client = data.getValueAt(self.getSibling("serviceCallTracker_Table").props.selection.selectedRow,'Client')
	serviceDate = data.getValueAt(self.getSibling("serviceCallTracker_Table").props.selection.selectedRow,'Date')
	engLastName = data.getValueAt(self.getSibling("serviceCallTracker_Table").props.selection.selectedRow,'EngLastName')
	receivedSR = data.getValueAt(self.getSibling("serviceCallTracker_Table").props.selection.selectedRow,'SRfromEng')
	sendReminder = data.getValueAt(self.getSibling("serviceCallTracker_Table").props.selection.selectedRow,'SendReminder')
	today = system.date.now()
	dateFormat = system.date.format(today,"MM/dd/yyyy")

	
	if receivedSR == "No" and sendReminder != '':
		smtp_server = "Email"
		emailLookup = system.db.runScalarQuery("SELECT Email FROM EngineerEmailListDatabase WHERE LastName = '%s'" %engLastName)
		engFirstName = system.db.runScalarQuery("SELECT FirstName FROM EngineerEmailListDatabase WHERE LastName = '%s'" %engLastName)
		fromAddr = "e@email.net"	
		emailSubject = client + " Service Report from " + serviceDate + " is outstanding"
	
		body = engFirstName + ",<br>" 
		body += "<br>"
		body += "The Servie Report in the subject line has not been turned in as of " +  dateFormat + "." + " This is a reminder to please attempt to get this report turned in, in a timley manner.<br>"
		body += "<br>"
		body += "If you have any questions/concerns regarding this email, please do not hesitate to let me know.<br>"
	
		system.net.sendEmail(smtpProfile=smtp_server,fromAddr=fromAddr,subject=emailSubject,body=body,html=1,to=emailLookup)

I have a second database that stores information about the technicians and that is where the Email address is pulled from
image

This all works as expected, when you select the row in my table and if the conditions are true, the email is sent with the correct data (client name, technician name, sent to correct email address).

But I don’t want to have to go through and select each row, from the table, and send the email out that way. I want to be able to select the button and an email is sent for each overdue report.

On your button, you would simply loop through your dataset and send the email for each row, if it matches the criteria you have setup

This is untested. You might have to change some stuff to get it working on your end (like the location of the table relative to where your button is)

table = self.getSibling("serviceCallTracker_Table")
data = table.custom.data	

today = system.date.now()
dateFormat = system.date.format(today,"MM/dd/yyyy")
smtp_server = "Email"
fromAddr = "e@email.net"

for row in range(data.rowCount):
    client = data.getValueAt(row,'Client')
    serviceDate = data.getValueAt(row,'Date')
    engLastName = data.getValueAt(row,'EngLastName')
    receivedSR = data.getValueAt(row,'SRfromEng')
    sendReminder = data.getValueAt(row,'SendReminder')

    if receivedSR == "No" and sendReminder != '':
        emailLookup = system.db.runScalarQuery("SELECT Email FROM EngineerEmailListDatabase WHERE LastName = '%s'" %engLastName)
        engFirstName = system.db.runScalarQuery("SELECT FirstName FROM EngineerEmailListDatabase WHERE LastName = '%s'" %engLastName)   
        
        emailSubject = client + " Service Report from " + serviceDate + " is outstanding"
        body = engFirstName + ",<br>" 
        body += "<br>"
        body += "The Servie Report in the subject line has not been turned in as of " +  dateFormat + "." + " This is a reminder to please attempt to get this report turned in, in a timley manner.<br>"
        body += "<br>"
        body += "If you have any questions/concerns regarding this email, please do not hesitate to let me know.<br>"

        system.net.sendEmail(smtpProfile=smtp_server,fromAddr=fromAddr,subject=emailSubject,body=body,html=1,to=emailLookup)