Saving a Report on Button Press

I'm trying to create a button in Vision that functions like a 'save as' for PDF reports.
My report is correctly configured and I can get it to generate and save on button press to a static location, but I want it to prompt the user for a file name, and location to save the report. I have this functionality for CSV files from a table and am trying to replicate this as a PDF. I'm sure it is something simple that i am missing.

im hoping to use system.file.saveFile or even JFileChooser but i get stuck at the same point with both options. I can successfully prompt the user for a location but it saves the PDF within another folder rather than the straight PDF.

# Get the current date
today =

# Define the fileDate based on the current date
fileDate =, "yyyy-MM-dd")
reportName = "Alarm_History_" + fileDate + ".pdf"

# Display a file dialog to save the PDF report
filePath = system.file.saveFile(reportName, ".pdf", "PDF Files")

if filePath:
    reportParameters = {"StartDate":, -24), "EndDate":}
    settings = {"path": filePath, "format": "pdf"}

    # Execute and distribute the report to the specified path
    result ="Alarm_History", project="DEV_RPF2_MKVI", parameters=reportParameters, action="save", actionSettings=settings)

    # Check if the report execution was successful
    if result:
        print("PDF report saved to: " + filePath)
        print("Report generation and distribution failed.")
    print("User canceled the file selection. Report generation and distribution canceled.")

any assistance would be greatly appreciated.

on a side note is it possible to restrict the window so files can't be deleted?

Don't use executeAndDistribute(). Use to return the PDF bytes, and save the file yourself (because it is Vision).