Skip to main content

Posts

Showing posts from February, 2024

Insert JavaScript and CSS code to APEX from PL/SQL

O One of my colleagues (lets name him Max) prepared a surprise for me. I had no idea where is the JavaScript code being placed on page. Turned out, there is an API for injecting JavaScript code from PL/SQL and you can do the same with CSS. That is not just an excellent hiding place, but it can be used if you need to attach these on page dynamically. Checkout the APEX_JAVASCRIPT api, especially the ADD_ONLOAD_CODE procedure. For example you can set the JavaScript variable from the PL/SQL. BEGIN APEX_JAVASCRIPT.ADD_ONLOAD_CODE ( p_code => 'variable_name = new_value;' ); END; / Better version would be to escape the value using ADD_VALUE (which is an equivalent of APEX_EXEC.ENQUOTE_LITERAL but for JavaScript) or APEX_JAVASCRIPT.ESCAPE function: BEGIN APEX_JAVASCRIPT.ADD_ONLOAD_CODE ( p_code => 'variable_name = ' || APEX_JAVASCRIPT.ADD_VALUE('new_value', p_add_comma => FALSE) || ';' ); END; /