Automatically Re-Enable APEX Automations After Deployment

Search for a command to run...

No comments yet. Be the first to comment.
Introduction One of the marquee features of APEX 26.1 was AI Interactive Reports. When I started testing this new feature, I was interested to see what was going on behind the scenes. In this post, I

Introduction One of the marquee features of APEX 26.1 is APEX AI Agents. APEX AI Agents allow you to use an LLM and your own PL/SQL and JS tools to perform actions on your data instead of just chattin

Introduction In my previous post, I looked at logging APEX AI Agent requests and responses with Request and Response handlers. Logging is the first step because it shows you what is actually moving th

Introduction Logging is one of the first things you need when building serious AI Agents. Without it, debugging quickly becomes guesswork. You can see the final answer, but not always why the model ch

Context management patterns from building agents in Oracle APEX

As you may know, when you deploy an APEX Application, APEX automatically disables all of the APEX Automations associated with that Application. This is perfectly fine in many scenarios, but when deploying to production, you nearly always want to restart all your Automations following the deployment. This post will describe two options for automating and re-enabling APEX Automations following a deployment.
This option involves creating a SQL script to loop through all Automations related to the APEX Application and re-activate them.
DECLARE
CURSOR cr_app_automations IS
SELECT app.application_id, app.workspace, atm.static_id
FROM apex_appl_automations atm
, apex_applications app
WHERE app.application_id = atm.application_id
AND app.alias = 'BACKGROUND-APEX';
BEGIN
-- Loop through all Automations for the Application.
FOR r_app_automation IN cr_app_automations LOOP
-- Set the Workspace / Security Group for the Application.
apex_util.set_security_group_id
(p_security_group_id => apex_util.find_security_group_id
(p_workspace => r_app_automation.workspace));
-- Enable the Automation.
apex_automation.enable
(p_application_id => r_app_automation.application_id,
p_static_id => r_app_automation.static_id);
END LOOP;
END;
The above script should be run after the APEX Application Deployment.
Another approach is to include the script as a Supporting Object Script, which will run automatically every time the Application is deployed.
Navigate to Application > Supporting Objects > Scripts > Install

Click the Create button:

Select ‘Create from Scratch’, and then click the Next Button:

Enter a name for the Script and click the Next button:

Copy and Paste the same script as option one above, and click the Create button.
The next time you import the APEX Application, you will get the Option to Install Supporting Objects. Click this button to run the script to re-activate your APEX Automations.


After this step is complete, you can check the status of the install scripts by clicking the Install Summary button.

If you check the status of the Automations in the newly installed App, they should all be Active.

If you import your app via the command line, you can call it apex_application_install.set_auto_install_sup_obj API to tell APEX to automatically run the supporting object scripts after the app has been imported.
BEGIN
apex_application_install.set_auto_install_sup_obj (p_auto_install_sup_obj => true);
END;
/
@f100.sql
This was a quick tip that will hopefully save time and prevent you from manually re-activating your APEX Automations after deploying an Application.