How to create oracle APEX plugins

Oracle APEX (Application Express) plugins are custom components that can be added to APEX pages to extend the functionality of the application. To create an APEX plugin, you will need to have an understanding of HTML, CSS, JavaScript, and PL/SQL. Here are the general steps to create an APEX plugin:

  1. Create a new plugin in the APEX builder by going to Shared Components > Plugins.
  2. Define the plugin attributes, such as the name, type and others.
  3. Create the PL/SQL package that will contain the plugin’s functions and procedures.
  4. Create the plugin’s JavaScript and CSS files.
  5. Add the plugin to a page by going to the page’s properties and selecting the plugin from the “Plugins” section.
  6. Test the plugin and make any necessary adjustments.

Let’s start building APEX plugins

here is an example of creating a simple APEX plugin that adds a button to a page and displays an alert message when the button is clicked:

  1. Create a new plugin in the APEX builder by going to Shared Components > Plugins,
  2. and clicking on the “Create” button. Fill out the form, such as the name and type of the plugin.
  3. Enter name, for example, “Sample Sweet Alert
  4. Enter Internal Name
  5. Select Type as Dynamic Action
  6. Create the PL/SQL package that will contain the plugin’s functions and procedures.
CREATE OR REPLACE PACKAGE my_plugin
AS
   FUNCTION render_fn (p_dynamic_action   IN apex_plugin.t_dynamic_action,
                       p_plugin           IN apex_plugin.t_plugin)
      RETURN apex_plugin.t_dynamic_action_render_result;
END my_plugin;
/
  1. Create the package body:
create or replace PACKAGE BODY my_plugin
AS
   FUNCTION render_fn (p_dynamic_action   IN apex_plugin.t_dynamic_action,
                       p_plugin           IN apex_plugin.t_plugin)
      RETURN apex_plugin.t_dynamic_action_render_result
   AS
      l_result   apex_plugin.t_dynamic_action_render_result;
   BEGIN
    APEX_JAVASCRIPT.ADD_LIBRARY(
        P_NAME        => 'js',
        P_DIRECTORY   => P_PLUGIN.FILE_PREFIX,
        P_VERSION     => NULL,
        P_KEY         => 'anything'
    );

   APEX_CSS.ADD_FILE(
        P_NAME        => 'css',
        P_DIRECTORY   => P_PLUGIN.FILE_PREFIX,
        P_VERSION     => NULL,
        P_KEY         => 'ssss'
    );
    l_RESULT.JAVASCRIPT_FUNCTION   := 'my_plugin.initialize';
    l_result.attribute_01          := p_dynamic_action.attribute_01;
    l_result.attribute_02          := p_dynamic_action.attribute_02;
    l_result.attribute_03          := p_dynamic_action.attribute_03;

      RETURN l_result;
   END render_fn;
END my_plugin;
  1. Create the plugin’s JavaScript file. This file will contain the JavaScript code that will be executed when the button is clicked.
var my_plugin = {
    initialize:function(){
    "use strict";
    
    var da=this;
    apex.debug.log('my_plugin.initialize',da);
    var message = da.action.attribute01;
    var title = da.action.attribute02;
    var icon = da.action.attribute03;
    console.log(message);
    
    function alert_fn (p_message){
        // swal(title, p_message); 
        swal({
            title: title,
            text: p_message,
            icon: icon,
            });

    }

    alert_fn(message);
    }
}
  1. Let’s invoke the external JS API. Sweet Alerts
  2. Refer to the API link to Plugin JS
  3. Add the plugin to a page by going to the page’s properties and selecting the plugin from the “Plugins” section.

Let’s try to use it on the page.

Why plugins?

Related Posts

Leave a Reply

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