bytesArray = system.report.executeReport(path="Rendering/Cookers/Cooker8", project="Copy_Of_Joslin_test_CJL", fileType="pdf")
body = "<HTML><BODY><H1>This is a big header</H1>"
body += "And this text is <font color='red'>red</font></BODY></HTML>"
recipients = ["christopher.Lang2@tyson.com"]
cc_recipients = [""]
smtp_server = "Outlook"
report= "Rendering/Cookers5/Cooker8.pdf"
bytesArray2=bytesArray
system.net.sendEmail(smtpProfile=smtp_server, fromAddr="ThisIsATest@gmail.com", subject="Here is the email!", body=body, html=1, to=recipients,attachmentNames=report, attachmentData=bytesArray, cc=cc_recipients)
I can not get the email to have the pdf of a report when i run system.report.executeReport
i am running this script on a button action so i dont know if that could be the problem or not also I am wanting eventual make a list of multiple reports and email multiple PDFs in the email
attachmentNames
and attachmentData
are documented as requiring a list of arguments:
https://docs.inductiveautomation.com/display/DOC81/system.net.sendEmail
You might just need to change the last line of your script where you're actually executing the call to wrap the attachment name (which probably shouldn't have slashes in it...) and attachment data variables in square brackets so that they end up in a list:
report= "Cooker8.pdf"
system.net.sendEmail(
smtpProfile=smtp_server,
fromAddr="ThisIsATest@gmail.com",
subject="Here is the email!",
body=body,
html=1,
to=recipients,
attachmentNames=[report],
attachmentData=[bytesArray],
cc=cc_recipients
)
bytesArray = system.report.executeReport(path="Rendering/Cookers/Cooker8", project="Copy_Of_Joslin_test_CJL", fileType="pdf")
bytesArray2 = system.report.executeReport(path="Rendering/Cookers/Cooker7", project="Copy_Of_Joslin_test_CJL", fileType="pdf")
x=[bytesArray,bytesArray2]
body = "<HTML><BODY><H1>This is a big header</H1>"
body += "And this text is <font color='red'>red</font></BODY></HTML>"
recipients = ["christopher.Lang2@tyson.com"]
cc_recipients = [""]
smtp_server = "Outlook"
report= "Rendering Cooker8.pdf"
system.net.sendEmail(smtpProfile=smtp_server, fromAddr="ThisIsATest@gmail.com", subject="Here is the email!", body=body, html=1, to=recipients,attachmentNames=[report], attachmentData=[x], cc=cc_recipients)
ok what you said was the issue now how would I put multiple reports in a list and pass that into the attachmentData
You need two flat lists (depth 1) with two items in each to send two reports as attachments.
So in your code sample there, x
is perfect for the attachmentData parameter- it's a flat list with two items.
The list of report names should be constructed similarly:
reportNames = ["Rendering Cooker8.pdf", "Rendering Cooker7.pdf"]
This syntax, wrapping bare expressions in square brackets to create a list, is known as a list literal.
All of the following are equivalent:
bytesArray = system.report.executeReport(path="Rendering/Cookers/Cooker8", project="Copy_Of_Joslin_test_CJL", fileType="pdf")
bytesArray2 = system.report.executeReport(path="Rendering/Cookers/Cooker7", project="Copy_Of_Joslin_test_CJL", fileType="pdf")
x=[bytesArray,bytesArray2]
x = [
system.report.executeReport(path="Rendering/Cookers/Cooker8", project="Copy_Of_Joslin_test_CJL", fileType="pdf"),
system.report.executeReport(path="Rendering/Cookers/Cooker7", project="Copy_Of_Joslin_test_CJL", fileType="pdf")
]
x = []
x.append(system.report.executeReport(path="Rendering/Cookers/Cooker8", project="Copy_Of_Joslin_test_CJL", fileType="pdf"))
x.append(system.report.executeReport(path="Rendering/Cookers/Cooker7", project="Copy_Of_Joslin_test_CJL", fileType="pdf"))
x = list()
x.append(system.report.executeReport(path="Rendering/Cookers/Cooker8", project="Copy_Of_Joslin_test_CJL", fileType="pdf"))
x.append(system.report.executeReport(path="Rendering/Cookers/Cooker7", project="Copy_Of_Joslin_test_CJL", fileType="pdf"))
It's also important to keep track of the 'depth' of the list. Python allows you to nest lists arbitrarily deep;
you can have a list that contains other lists (that contain other lists) repeatedly.
So in the last line of your code there, you're passing attachmentData=[x]
- that's wrong, because that's wrapping your flat list of two reports into another list - [[reportPdf, reportPdf2]]
. The scripting function won't be able to handle it, so that'll lead to errors.
In addition, attachmentNames=[report]
is constructing a flat list (good) but with only one item (bad), so the scripting function won't "know" what name to give to each attachment data, and that will also lead to errors.
1 Like
Works perfectly now thank you for the explanation really helped!