APEX

Use APEX API to display version infos in your apps

published on

Many projects require the current version of the application. Oracle APEX applications have a version identifier stored in the application settings by default. This is usually "Release 1.0". In the past, I have stored a version information in semantic form and a log from the commits, matching this version, with the release. To do this, I wrote the version information in a release table during deployment and stored a global application process that reads this information when the application or session is started and writes it to an application item that then displays the corresponding version in the settings at runtime using substitution notation.

application properties showing substitution variable in version field

For some applications, this is quite an overhead.

Since version 23.1, APEX also offers a solution for this. It is now possible to set the version via API. Setting the workspace and actually calling the API is sufficient here.

begin
  apex_application_install.set_workspace (p_workspace => 'DEMO' );
  apex_application_admin.set_application_version ( p_application_id => 1000,
										           p_version        => 'Release 1.0');
end;

Actually quite simple.

The whole thing makes even more sense if you include this call in your CI/CD pipeline. If you use dbFlow, for example, you could simply write a global hook script that calls this API directly at the end of a deployment.

VS Code Treeview with a post hook file selected

This script is called by dbFlow at the end (post) of the main installation. The project here is called TAYRA and the schema used to import the applications is TAYRA_APP. This is a multi-schema setup that maps to a classic 3-tier model. dbFlow always calls these scripts with the parameters for the version and the import mode. Therefore, such a script can look something like this.

set define '^'
set concat on
set concat .
set verify off
set serveroutput on
set linesize 2000
set wrap off
SET TERMOUT OFF
COLUMN 1 NEW_VALUE 1
COLUMN 2 NEW_VALUE 2

SELECT '' "1" FROM dual WHERE ROWNUM = 0;
SELECT '' "2" FROM dual WHERE ROWNUM = 0;

-- Set params to internal vars
DEFINE _parameter_01 = ^1 "0.0.0"
DEFINE _parameter_02 = ^2 "undefined"

define VERSION = ^_parameter_01
define MODE = ^_parameter_02

SET TERMOUT ON
PROMPT ********************************************************************
PROMPT * VERSION    <^VERSION>
PROMPT * MODE       <^MODE>
PROMPT ********************************************************************

set timing on;
prompt ............................................................................
prompt ............................................................................
prompt ..                                                                        ..
prompt ..      Setting Versioninfos                                              ..
prompt ..                                                                        ..
prompt ............................................................................
prompt ............................................................................
begin
  apex_application_install.set_workspace (p_workspace => 'TAYRA' );
  for apps in (select column_value
                 from table(apex_string.split_numbers('1000:2000:3000', ':')))
  loop
    apex_application_admin.set_application_version(p_application_id => apps.column_value,
                                                   p_version        => 'Release ^VERSION ('||to_char(sysdate, 'DD.MM.YYYY HH24:MI')||')');
  end loop;
end;
/

After installing, the corresponding applications show the appropriate version.

APEX default footer showing version number

I tend to always display a version identifier to give a context to screenshot which shows a part or the app.