Oracle APEX – Calling a Modal Page from Javascript

Goal: Call a modal page from Javascript code (Dynamic Action or other context) and pass javascript values as parameters.

If the parameter value is stored in a JS variable, no need to call an Ajax process.

Just write this kid of statement:
(assuming the modal page is 50)

var pid = '123456';
var purl = "f?p=&APP_ID.:50:&APP_SESSION.:::50:P50_ID:P_ID";   
purl = purl.replace('P_ID', pid);    
apex.navigation.redirect (purl);

It’s important to do the replacement of the parameter P_ID after declaring the purl variable, because APEX will parse the purl variable before the JS code be evaluated. (otherwise, the pid parameter value is put a the very end of the generated JS code (cf below)

Dont’ enclose the P50-ID with # (ie: #P50_ID#) because that doesn’t work.

The JS code generated (before variable substitution) looks like that:

javascript:apex.navigation.dialog('/ords/r/demo/xxxxx/change-owner?p50_id=P_ID&clear=50&session=109433551444631&dialogCs=xxxxxxxxxxxxxxxxxxxxxxxxxx',{title:'Change Owner',height:'auto',width:'720',maxWidth:'960',modal:true,dialog:null},'t-Dialog-page--standard '+'',this);