Scheduled report with scripted parameters

Hi All

I use the reporting module to display OEE data for a suite of CNC machines.

I have a single report set up. I call it from a script and pass in parameters to display data for each machine. Currently the report generation is AdHoc - a user can request a report for a machine by setting the date range, selecting the machine and then hitting a button. A gateway script then queries the historian, processes the data and passes it to the report.

I would like to also include a scheduled report that emails out a pdf with the OEE for the past week. I figured that I would just use “runScript” under each of the parameters. However, this does not work and gives me “Error parsing default value expression for parameter”.

Can anyone suggest how to achieve this function? I do not have tags that contain the required data. I could do so if I set up an earlier scheduled task to query the historian but this seems a little complicated. I have tested the referenced scripts but my syntax could well be at fault…

Cheers!

You need a gateway event script (scheduled or timer) to set up your parameters, then use system.report.executeAndDistribute() (still in the gateway script).

1 Like

Very cool! Thanks @pturmel

My script. Does anyone know how to add multiple reports to a single email? I’d rather not create a new report with multiple pages as this results in more complexity elsewhere.

# List of the CNC machines
machines = ["1", "2", "3"]

# List of recipients
emails = ["email@domain"]

# Load the end date
endDate = system.date.now()

# Load the start date
startDate = system.date.addDays(endDate, -5)	

# Run this for each machine in the list
for machName in machines:
		
	# Build the tag path
	udtPath = "[tags]Machine Shop/CNCs/" + machName

	# Build the subject string
	subject = machName + " OEE report " + str(endDate)

	# Set the attachment name
	attachName = machName + " " + str(endDate)

	# Get the util and downtime data
	utilData, dtimeData = machineShop.cncOEE.calcVar(udtPath, startDate,endDate)

	# E-mail the report
	system.report.executeAndDistribute(path="Machine Shop/Utilisation Report",project="projectname", \
	parameters={'machName':machName, 'utilData':utilData,'dtimeData':dtimeData,'endDate':endDate,'startDate':startDate, 'userName':"username"},\
	action="email", actionSettings = {"to":emails, "smtpServerName":"SMTP Relay","from":"scada email", "subject":subject, "attachmentName":attachName})

and another question. My code works fine for email addresses. If I swap to using roles, the email isn't send and the gateway shows the following errors that appear to suggest that the email address is invalid. I have specified the a role with multiple users. They all have valid email addresses. Any ideas?

# E-mail the report (roles)
system.report.executeAndDistribute(path="Machine Shop/Utilisation Report",project="project_name", \
parameters={'machName':machName, 'utilData':utilData,'dtimeData':dtimeData,'endDate':endDate,'startDate':startDate, 'userName':"username"},\
action="email", actionSettings = {"useRoles":True, "userSource":"default", "roles":roles, "smtpServerName":"SMTP Relay", "from":"scada email", "subject":subject, "attachmentName":attachName})

Error in sending email for report config Email
javax.mail.internet.AddressException: Illegal address

system.report.executeAndDistribute - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)

Your “from” is not a valid email address.

Meanwhile, consider using system.report.execute to obtain the PDF bytes of each complete report, and add them as attachements to combined email. Using system.net.sendEmail(), that is.

Sorry for the slow reply. I replaced the from email before posting the code on this forum. With a valid email, I still cannot get this code to work. I will test out system.report.execute. Thanks.

I have just tested system.report.execute. I was able to send a single email with multiple attachments.

Note for anyone else struggling. I had to specifically state the SMTP server address. Unlike with
system.report.executeAndDistribute, a string reference to the SMTP server set up in the ignition web pages did not work for me.

Thanks @pturmel for your help.

1 Like