# MenuTree Report

**URL:** <https://forum.inductiveautomation.com/t/menutree-report/77073>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [July 28, 2023, 3:29pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073 "2023-07-28T15:29:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josue\_Cuadras](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/josue_cuadras/32/59915_2.png) [@Josue\_Cuadras](https://forum.inductiveautomation.com/u/Josue_Cuadras)\
**Post date:** [July 28, 2023, 3:29pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/1 "2023-07-28T15:29:49Z")

</div>

Is it possible to download a Report to the user session using directly the MenuTree?

---

<div class="post-metadata">

**Author:** ![Josue\_Cuadras](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/josue_cuadras/32/59915_2.png) [@Josue\_Cuadras](https://forum.inductiveautomation.com/u/Josue_Cuadras)\
**Post date:** [July 28, 2023, 4:19pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/2 "2023-07-28T16:19:37Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/2/82e09f785ec835492cb661986cf16194be26e847.png)

I mean that when clicking on the report button, a report is generated and the user can download it.

The report is already made with the reporting tool.

Like a component event.

---

<div class="post-metadata">

**Author:** ![Liam\_Dietrich](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@Liam\_Dietrich](https://forum.inductiveautomation.com/u/Liam_Dietrich)\
**Post date:** [July 28, 2023, 4:26pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/3 "2023-07-28T16:26:45Z")

</div>

Assuming you can send a message handler on selection with the report path and file type, you should be able to modify the following code to download a report. Let me know if that helps.

```auto
    reportPath = payload["reportPath"]
	fileType = payload["fileType"]
	if fileType:
		try:
			reportPath = reportPath 
			parts = path.split("/")
            fileName = parts[-1]
			if reportPath in system.report.getReportNamesAsList():
				bytesArray = system.report.executeReport(path=reportPath, fileType=fileType)
				system.perspective.download(fileName+"."+fileType, bytesArray)
		except Exception as e:
			logger = system.util.getLogger("Reports Error")
			logger.info("Failed to download report. Error: " + str(e))

```

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [July 28, 2023, 4:57pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/4 "2023-07-28T16:57:22Z")

</div>

On the menu tree onItemClicked component event add a script action with something like this:

```auto
	if event.path[0] == 3:
		params = {"start": '7/28/2023' , "end": '7/29/2023'}
		bytesArray = system.report.executeReport(path="ReportPath", project="ProjectName", parameters=params, fileType="xlsx")
		system.perspective.download("ReportName.xlsx", bytesArray)

```

This example will generate and prompt to download if you click on the 4th menu item on the top level, you would need to modify it to fit which item your report item is at aswell as the report and parameters.

---

<div class="post-metadata">

**Author:** ![Josue\_Cuadras](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/josue_cuadras/32/59915_2.png) [@Josue\_Cuadras](https://forum.inductiveautomation.com/u/Josue_Cuadras)\
**Post date:** [July 28, 2023, 5:00pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/5 "2023-07-28T17:00:37Z")

</div>

This is the answer I was looking for!!

Thank you, works like a charm.

---

<div class="post-metadata">

**Author:** ![Josue\_Cuadras](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/josue_cuadras/32/59915_2.png) [@Josue\_Cuadras](https://forum.inductiveautomation.com/u/Josue_Cuadras)\
**Post date:** [July 28, 2023, 5:26pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/6 "2023-07-28T17:26:45Z")

</div>

```auto
if event.path [0, 6] == 1:
        data = system.report.executeReport("assy_kenmex/Kenmex Monitoreo/Kenmex Monitoreo", fileType = "pdf")
        system.perspective.download("Kenmex.pdf", data)

```

Is there any error on the code?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 28, 2023, 5:32pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/7 "2023-07-28T17:32:10Z")

</div>

> [@Josue\_Cuadras](#):
>
> `event.path [0, 6]`

What are you trying to do with this? (It isn't valid syntax for jython.)

---

<div class="post-metadata">

**Author:** ![Josue\_Cuadras](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/josue_cuadras/32/59915_2.png) [@Josue\_Cuadras](https://forum.inductiveautomation.com/u/Josue_Cuadras)\
**Post date:** [July 28, 2023, 5:36pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/8 "2023-07-28T17:36:36Z")

</div>

The item path for the “Report” section on the MenuTree is [0, 6, 1] as you can see:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/8/1830a1906b91856a83d609048d8c4faf3ece3fda.png)

---

<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:** [July 28, 2023, 5:38pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/9 "2023-07-28T17:38:27Z")

</div>

No, the path to what you are showing in the screenshot is `items[0]items[6]items[1]`.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 28, 2023, 5:41pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/10 "2023-07-28T17:41:34Z")

</div>

I suspect what you are trying is:

```auto
if event.path == [0, 6, 1]:

```

but you might need:

```auto
if event.path[0] == 0 and event.path[1] == 6 and event.path[2] == 1:

```

---

<div class="post-metadata">

**Author:** ![Josue\_Cuadras](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/josue_cuadras/32/59915_2.png) [@Josue\_Cuadras](https://forum.inductiveautomation.com/u/Josue_Cuadras)\
**Post date:** [July 28, 2023, 5:44pm UTC](https://forum.inductiveautomation.com/t/menutree-report/77073/11 "2023-07-28T17:44:50Z")

</div>

Yes! This is what I was trying to achieve Thank you! 😭
