# Won't attach PDF when I use system.report.executeReport

**URL:** <https://forum.inductiveautomation.com/t/wont-attach-pdf-when-i-use-system-report-executereport/74799>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [June 8, 2023, 8:51pm UTC](https://forum.inductiveautomation.com/t/wont-attach-pdf-when-i-use-system-report-executereport/74799 "2023-06-08T20:51:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christopher\_Lang](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/christopher_lang/32/55614_2.png) [@Christopher\_Lang](https://forum.inductiveautomation.com/u/Christopher_Lang)\
**Post date:** [June 8, 2023, 8:51pm UTC](https://forum.inductiveautomation.com/t/wont-attach-pdf-when-i-use-system-report-executereport/74799/1 "2023-06-08T20:51:01Z")

</div>

```auto
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

```auto

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 8, 2023, 9:04pm UTC](https://forum.inductiveautomation.com/t/wont-attach-pdf-when-i-use-system-report-executereport/74799/3 "2023-06-08T21:04:33Z")

</div>

`attachmentNames` and `attachmentData` are documented as requiring a _list_ of arguments:  
[https://docs.inductiveautomation.com/display/DOC81/system.net.sendEmail](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:

```python
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
)

```

---

<div class="post-metadata">

**Author:** ![Christopher\_Lang](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/christopher_lang/32/55614_2.png) [@Christopher\_Lang](https://forum.inductiveautomation.com/u/Christopher_Lang)\
**Post date:** [June 9, 2023, 11:49am UTC](https://forum.inductiveautomation.com/t/wont-attach-pdf-when-i-use-system-report-executereport/74799/4 "2023-06-09T11:49:48Z")

</div>

```auto
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

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 9, 2023, 3:29pm UTC](https://forum.inductiveautomation.com/t/wont-attach-pdf-when-i-use-system-report-executereport/74799/5 "2023-06-09T15:29:09Z")

</div>

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:

```python
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.

---

<div class="post-metadata">

**Author:** ![Christopher\_Lang](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/christopher_lang/32/55614_2.png) [@Christopher\_Lang](https://forum.inductiveautomation.com/u/Christopher_Lang)\
**Post date:** [June 9, 2023, 3:59pm UTC](https://forum.inductiveautomation.com/t/wont-attach-pdf-when-i-use-system-report-executereport/74799/6 "2023-06-09T15:59:20Z")

</div>

Works perfectly now thank you for the explanation really helped!
