TLDR:

  • Create hidden page item in the report region
  • Define a dynamic action to dynamically generate the desired file name
  • Pass page item to report region
  • Set page item as filename in attributes tab using the “&PX_NAME.” format. (”&” and “.” are very important!)
  • Download report with dynamic filename

Background

Interactive Reports in Oracle APEX come with a lot of very useful features.

One of these features is the report export as Excel, CSV or PDF. By default, the name of the report is taken as the file name. However, sometimes it is necessary to name the file name dynamically, e.g. if the current date should appear in the file name. In this blog article I want to show you how to use dynamic file names in Oracle APEX.

A Demo can be found here: https://apex.oracle.com/pls/apex/r/jpdev/oracle-jet-showcase/unicorn-companies-report

For this example, I use the same table with Unicorn Companies that I used in my article on Sankey charts. You can find the article here: https://jdpenner.de/apex/working-with-jet-diagrams-in-oracle-apex/

Basically the solution is very simple and can be implemented in only 3 steps:

  1. Create a page item that will be used for the filename.
  2. Define Dynamic Action, which sets the filename dynamically
  3. Pass the page item as file name to the report.

Creating the page item

For this example I assume that a page with a report already exists.
First, we create a Hidden Page Item in the Report Region.
In my case I call it P5_DYNAMIC_FILE_NAME.

I want to name my report with the current cate and Unicorn Companies. So that the report always gets the right name, I create a cynamic action in the next step that writes the file name into the page item during page load.

Defining the dynamic action

SELECT	CONCAT(TO_CHAR ( SYSDATE, 'YYYY-MM-DD'),'_Unicorn-Companies')	AS Report
FROM    dual;

The “Set Value” assigns the file name dynamically to the page item.

Passing the page item to the report

In the last step we only have to pass the page item as file name to the report.

To pass the Filename to the report region the P5_DYNAMIC_FILE_NAME Item has to be submitted in the source tab.

Navigate to the Attributes Tab in the Report Region and pass the Page Item as the Filename

The correct format is “&PX_NAME.” . So in our case “&P5_DYNAMIC_FILE_NAME.”

Testing

Now all we have to do is download the report and check the filename.

In my case I want to download the report as an Excel File, but the filename works for all other filetypes as well.

Categories:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *