MenuTree Report

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

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.

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.

    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))
1 Like

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

	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.

1 Like

This is the answer I was looking for!!

Thank you, works like a charm.

1 Like
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?

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

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

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

I suspect what you are trying is:

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

but you might need:

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

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