Pages

Tuesday, June 5, 2012

changing script_name (/apex) in apex

Get server URL in Apex



The OWA_UTIL package contains utility subprograms for getting the value of environment variables. Specifically the OWA_UTIL.GET_CGI_ENV function returns the value of CGI environment variables, like REQUEST_PROTOCOL, HTTP_HOST, SERVER_PORT and SCRIPT_NAME, this last one to get the mod_plsql cartridge and the database access descriptor name.

Usage:

view plaincopy to clipboardprint?
owa_util.get_cgi_env('REQUEST_PROTOCOL')
owa_util.get_cgi_env('HTTP_HOST')
owa_util.get_cgi_env('SERVER_PORT')
owa_util.get_cgi_env('SCRIPT_NAME')


You can quickly test these values creating a PL/SQL Dynamic Content region like this:

view plaincopy to clipboardprint?
BEGIN
HTP.p ( 'Apex URL: '
|| OWA_UTIL.get_cgi_env ('REQUEST_PROTOCOL') || '://'
|| OWA_UTIL.get_cgi_env ('HTTP_HOST') || ':'
|| OWA_UTIL.get_cgi_env ('SERVER_PORT') || '/'
|| OWA_UTIL.get_cgi_env ('SCRIPT_NAME') || '/'
);
END;


Now to complete the URL you just need to append the well known f function with the right values. In case you have forget, here is the Apex f function URL Syntax:

view plaincopy to clipboardprint?
f?p=App:Page:Session:Request:Debug:ClearCache:itemNames:itemValues:PrinterFriendly

No comments:

Post a Comment