PDF Report send to email

Hello guys,

I'm trying to send a pdf report as an email attachment. The script will run according to a schedule, the report will be generated with "system.report.executeReport".

Everything work until I add my "attachmentData" (PDF file) and I receive the next error.

com.inductiveautomation.ignition.common.script.JythonExecException
Traceback (most recent call last):
File "function:runAction", line 32, in runAction
AttributeError: 'array.array' object has no attribute 'getBytesPDF'

caused by org.python.core.PyException

Traceback (most recent call last):
File "function:runAction", line 32, in runAction
AttributeError: 'array.array' object has no attribute 'getBytesPDF'

Ignition v8.1.17 (b2022051210)
Java: Azul Systems, Inc. 11.0.15

Script

#content, recipients
	BuildHTML = "<html><body><p> Test</p></body></html>"   
	subject = 'test'
	body = BuildHTML	
	to = ['xxxxxxxxxxx']
	
	#try to build report
	a = system.report.executeReport(path="test", project="xxxxxxxx", fileType="pdf")
	attachmentNames = ['test.pdf']
	
	attachmentData=[a.getBytesPDF()] #Make into PDF data for email
	
	#send email function
	sendmail(subject, body, to, cc = None , bcc = None, attachmentNames = attachmentNames, attachmentData = attachmentData)

*script run with no problem if I try to send it with no attachemnt

Best Regards,

Paul

executeReport is already handing you back a byte array. You don’t need to getBytesPDF.

#try to build report
reportData = system.report.executeReport(path="test", project="xxxxxxxx", fileType="pdf")
attachmentNames = ['test.pdf']

attachmentData=[reportData]
2 Likes

Worked perfectly!

Thanks :smiley: