Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
probably working on an APEX Plugin

Stefan Dobre stefandobre

💭
probably working on an APEX Plugin
View GitHub Profile
View apex-mle-example-3.js
const marked = requireModule('marked');
// library-specific options
marked.setOptions({
headerIds: false
});
apex.env.P5_HTML = marked(apex.env.P5_MARKDOWN);
View apex-mle-example-1.js
// calling our custom requireModule function
const qrcode = requireModule('qrcode');
// library specific options
const code = qrcode(4, 'L');
code.addData(apex.env.P1_QR_DATA);
code.make();
// saving the base64 result into a page item of type Display Image
apex.env.P1_QR_CODE = code.createDataURL(4);
View apex-mle-require-module.js
// fetch the library from the table
const loadFromDatabase = (moduleName) => {
const result = apex.conn.execute(`
select source
  from javascript_modules
  where module_name = :name
`, {
name: moduleName
View apex-mle-get-libraries.sql
declare
type module_t is table of varchar2(100) index by varchar2(100);
l_modules module_t := module_t();
l_module varchar2(100);
l_code clob;
begin
/* store the name and location of each library that is to be imported */
l_modules('qrcode') := 'https://cdnjs.cloudflare.com/ajax/libs/qrcode-generator/1.4.4/qrcode.min.js';
l_modules('validator') := 'https://cdnjs.cloudflare.com/ajax/libs/validator/13.5.2/validator.min.js';
l_modules('marked') := 'https://cdnjs.cloudflare.com/ajax/libs/marked/1.2.9/marked.min.js';
View apex-mle-create-table.sql
create table javascript_modules
( module_name varchar2(100) primary key not null
, source clob not null
);
View apex-mle-pre-rendering-page.js
console.log(variable1); // error: variable1 is not defined
console.log(globalThis.variable1); // undefined
console.log(globalThis.variable2); // 200
View apex-mle-ajax.js
/*
In case the browser asynchronously called the server via AJAX,
this is how we can handle that request in JavaScript (MLE)
*/
let response = {};
try {
// execute any business logic here
apex.conn.execute();
// dummy response
View apex-mle-after-submit.js
// getting page item values
const empno = apex.env.P1_ID;
const salary = apex.env.P1_SAL;
// executing DML operations
apex.conn.execute('update emp set sal = :sal where empno = :empno', {
sal: salary,
empno: empno 
});
View apex_202_cke5_js_init_code.js
// followup to this conversation https://stefandobre.com/a-closer-look-at-the-rich-text-editor-of-orclapex-20-2/
function(options) {
options.editorOptions.toolbar = {
items:[
'heading',
'|', 'code', 'codeBlock', 'blockQuote',
'|', 'bold', 'italic', 'underline', 'strikethrough', 'fontfamily', 'fontsize', 'RemoveFormat', 'link',
'|', 'numberedList', 'bulletedList', 'outdent', 'indent', 'Alignment',
'|', 'InsertTable', 'fontColor', 'fontBackgroundColor',
'|', 'PageBreak', 'HorizontalLine', 'todoList', 'undo', 'redo'