When building an Oracle APEX application, one of the most used regions is the Classic Report. This region allows us to configure a report that returns the results of any SQL query.
These results can be presented to the user in different ways, taking into account the intended result. One of the most used formats is, of course, the report in tabular format:
Among the various options for configuring a Classic Report is the possibility to change the format of the columns returned. One of these possibilities is the option of configuring one, several or all columns to the Link format. This link can redirect the user to a page within the same application, to a page in another application within the same workspace, or to a web link.
This configuration is very simple and with 4 or 5 clicks, you quickly get a report with the same aspect of the previous one, but with all its columns defined as Link:
This link can be independent between the different columns, for example, the “Tipo” column can forward the user to a page in the current application, the “Plataforma” column to a page in another application and the “Componente” column to a page on the web like www.google.pt.
And if only one link per column is not enough and what you want is something more dynamic, for example, if the "Tipo" column has the value "Boas práticas", the destination of the link is different from the destination of the link of the value is "FAQ"?
This situation is not so simple, it is necessary to resort to other more laborious alternatives, making use of the construction of declared links.
Option A - Use a Branch Process
Step 2: Define the "setItems" function.
Create a Dynamic Action (DA) associated with the last Item to be set in the "setItems" function, in this case the “P532_TYPE”:
This DA is set to be triggered at the time this item changes its value, which will occur as soon as the line “apex.item(“P532_TYPE”).SetValue(type);” is executed:
Set the True condition of this DA with a Submit Page action:
This action simply submits our webpage, that is, reloads the page with the Items having already the new values assigned.
Note: It is important for the DA to be associated with the last item to be changed in the setItems function, because as the values are assigned in the same order that is declared in the function, we ensure that the DA is only triggered after all values have already been changed.
Create a Branch type process (this type of process redirects the application to different pages):
Set the processing point as “After Submit” so that the process runs right after the page is submitted. Set the Behavior type to “Function Returning a URL (Redirect)”:
In this function, all the target possibilities that we intend for our report are defined, according to the values of the Items and returning a URL to an APEX page (different from the “normal” URLs) with the function “APEX_PAGE.GET_URL”.
Option B – Define a hidden column in the report query with the link
Step 1: Add to the select query that feeds our report, a column that stores our destination URL using the defined options:
Step 2: Hide this column from the user:
Step 3: Now that we have the desired link value saved in the URL column, we define that the content of this column is the URL to which we want to navigate when we click each line:
In short: in each row of our report, we have a hidden column whose value is a dynamic URL, defined by the values of the other columns of the same row. When we select a report row, the chosen column invokes the link that is stored in the respective “URL” column.
Oracle APEX contains several very useful options that allow us to create applications with powerful features that are easily configurable. However, we are not always able to replicate all the requirements of our applications with these same integrated options. When that happens, with some knowledge of HTML, CSS and Javascritp/Jquery, and some out of the box thought, we can achieve our goals.
These are just two examples of how to achieve functionality that is not yet integrated from the start with APEX. Another option, not described, is the construction of an additional page, whose only function is to receive the values of the report and redirect the user to the final page according with these same values. Option B is, at first glance, simpler than solution A. The problem is that it requires a change to the query of our report, which may have a greater impact on the performance of the application, in addition to some developers may find this solution less clean.
None of the solutions presented are perfect, mainly because all intended cases have to be hardcoded. But for some cases, necessarily simpler, these two options can be a good alternative for those who need to navigate to different pages, according with the value of a column within a Classic Report.