1. Overview
This blog talks about the setting session state value for application item using the JavaScript function in Oracle APEX.
2. Technologies and Tools Used
The following technologies have been used to achieve this functionality,
- JavaScript
- PLSQL
- APEX
3. Use Case
The requirement is to set the session state value for the application item without page submit.
Actually, there are many ways to achieve this scenario. Here, we have taken the JavaScript function to set the session state value.
4. Architecture
Follow the steps to set the session state value using JS,
Step 1: Create an application item in which you want to set a value at the session-level. E.g. APP_USER_ID
Step 2: Create an application process(SET_APPITEM_VAL) in the application shared component,
BEGIN
IF apex_application.g_x01 = ‘APP_USER_ID’
THEN
:app_user_id := apex_application.g_x02;
END IF;
END;
Step 3: Go to the target page and put the following code in the Function and Global Variable Declaration under the JavaScript section which will be available in the page property,
JS:
//Use this function to set session state for application item
function setAppItemSessionState(AppItemName,AppItemVal){
apex.server.process(
“SET_APPITEM_VAL”,
{
x01: AppItemName,
x02: AppItemVal
},
{
async: false, // change here if you need sync/async
“dataType”: “text”,
“success”: function(data){
void(0);
console.log(data);
}
}
);
}
Step 4: Finally, based on the scenario, call this function using button action / any JavaScript event,
setAppItemSessionState(‘APP_USER_ID’,’1000’);