How to add a dynamic action that will redirect to another page by executing JavaScript Code?
I finally found out how to do this. The Request of the button (specifically the dynamic action of the button) was not set to the button name because the 'Request/Button Name' of the 'Submit Page' true action was not set to the name of the button.
Make sure in the dynamic action to add this information under 'Settings'. The branch should be placed to 'Submit: before Processing' with the condition 'Request = Expression 1' with Expression 1 equaling the button name!
Redirect/Refresh Page Using Dynamic Action - Oracle Apex 21.1
I'm not sure that will ever work - you can't do a redirect from within pl/sql in a dynamic action process. The pl/sql code is running in the background and cannot redirect the page. There are 2 options
- Change true action on page 7 to submit page and add a branch to redirect to the url of your choice
- Redirect using javascript (google it, you'll find several links on that)
How to attatch Dynamic Action or Process to a Menu Popout list item - APEX 21.1
There isn't a built-in solution for this unfortunately. There is a good blog post by John Snyders that describes a way of building this yourself.
I have also built some similar functionality, which I have a demo of here. This uses a bespoke table to store the menu options, and makes an AJAX call when the menu is opened to get the appropriate menu entries to display. These can be conditional e.g. the "Calculate commission" menu entry is only applicable to employees with job='SALESMAN'.
Tablescreate table report_menus
( menu_name varchar2(30),
constraint report_menus_pk primary key (menu_name)
);
create table report_menu_entries
( menu_name varchar2(30) not null enable,
entry_title varchar2(100) not null enable,
entry_target varchar2(1000) not null enable,
display_sequence number,
condition_type varchar2(30),
condition_expression varchar2(4000),
constraint report_menu_entries_pk
primary key (menu_name, display_sequence),
constraint report_menu_entries_fk1
foreign key (menu_name)
references report_menus (menu_name)
);
(Table REPORT_MENUS is there for completeness but doesn't do much in this demo).
Sample dataFor my example I created a single menu called 'EMPLOYEE_MENU' with 2 options:
insert into report_menu_entries values
( 'EMPLOYEE_MENU',
'Update',
'f?p=&APP_ALIAS.:3:&SESSION.::&DEBUG.:3:P3_EMPNO:<pk>',
1,
'NOT_EXISTS',
'select * from emp where empno=<pk> and job = 'PRESIDENT''');
insert into report_menu_entries values
( 'EMPLOYEE_MENU',
'Calculate commission',
'javascript:alert('Not yet implemented');',
2,
'EXISTS',
'select * from emp where empno=<pk> and job='SALESMAN''');
I have invented a special placeholder <pk>
which I use wherever I want to plug in the primary key of the record we are on (i.e. the EMPNO in this demo). This is required in the target URL and in conditions that depend on the data.
In the report, I create a dummy column for the menu by selecting null as menu
. I make this into a Link with a target URL of #
(we don't need the target really) and these properties:
Property | Value |
---|---|
Link text | <span class="fa fa-navicon" aria-hidden="true" title="report menu"></span> |
Link attributes | class="report-menu" data-key="#EMPNO#" data-menu="EMPLOYEE_MENU" |
Alert message after submit and validation page in oracle apex
There are different ways you could approach this. You're currently using a mix of Dynamic Actions and page-level validations and processes that aren't going to play well together. I suggest you move all the logic to Dynamic Actions. Here are step by step instructions to do what I think you're trying to do. You can learn from this and then integrate what you want back to your solution.
- Create a new blank page. Mine was page 17. You'll need to update references to "P17" with your page number if it's different. Disable the page level attribute Warn on Unsaved Changes to prevent prompts before the redirect to Google.
- Add a new HTML region to the page.
- Add a new item to the region. Set Name to P17_FIRST_NAME and leave the default Type of Text Field.
- Add a new item to the region. Set Name to P17_LAST_NAME and leave the default Type of Text Field.
- Add a new item to the region. Set Name to P17_RESULT, Type to Hidden, and Value Protected to No. This item will be used to transfer messages from the server to the client via Ajax.
- Add a button to the region. Set Name to RUN_PROCESS and Action to Defined by Dynamic Action.
- Create a new Dynamic Action that fires when the button is clicked. The easiest way to do this is to right-click the button and select Create Dynamic Action. Set the Name to RUN_PROCESS clicked.
Select the Show action that was created by default for the Dynamic Action. Set Action to Execute PL/SQL Code and copy-paste the following code into the PL/SQL Code attribute.
declare
l_result_obj json_object_t := json_object_t();
l_errors_arr json_array_t := json_array_t();
l_error_obj json_object_t;
begin
if :P17_FIRST_NAME is null
then
l_error_obj := json_object_t();
l_error_obj.put('pageItem', 'P17_FIRST_NAME');
l_error_obj.put('message', 'First Name is required.');
l_errors_arr.append(l_error_obj);
end if;
if :P17_LAST_NAME is null
then
l_error_obj := json_object_t();
l_error_obj.put('pageItem', 'P17_LAST_NAME');
l_error_obj.put('message', 'Last Name is required.');
l_errors_arr.append(l_error_obj);
end if;
if l_errors_arr.get_size() > 0
then
l_result_obj.put('status', 'error');
l_result_obj.put('errors', l_errors_arr);
:P17_RESULT := l_result_obj.to_string();
return;
end if;
null; -- do "success" processing here
l_result_obj.put('status', 'success');
l_result_obj.put('message', 'Hi ' || :P17_LAST_NAME || ' ' || :P17_LAST_NAME ||
'! You will now be redirected to Google.');
:P17_RESULT := l_result_obj.to_string();
end;As you can see, the validations are now being done inside the process. The PL/SQL code is making use of the JSON types introduced with Oracle 12.2. If you're on an older version of the database, you can adapt the code to use APEX_JSON instead.
- While still in the Execute PL/SQL Code action, set Items to Submit to P17_FIRST_NAME,P17_LAST_NAME and Items to Return to P17_RESULT. This is how you can transfer values from the page into session state before the process executes and then back to the page after the process finishes executing.
- Create a new Dynamic Action that fires on the Change event of P17_RESULT. The easiest way to do this is to right-click the item and select Create Dynamic Action. Set the Name to P17_RESULT changed.
Select the Show action that was created by default for the Dynamic Action. Set Action to Execute JavaScript Code and copy-paste the following code into the Code attribute.
var result = JSON.parse($v('P17_RESULT'));
apex.message.clearErrors();
if (result.status === 'error') {
for (var idx = 0; idx < result.errors.length; idx++) {
result.errors[idx].type = 'error';
result.errors[idx].location = ['page', 'inline'];
result.errors[idx].unsafe = false;
}
apex.message.showErrors(result.errors);
} else if (result.status === 'success') {
apex.message.alert(result.message, function(){
apex.navigation.redirect('https://google.com');
});
}The JavaScript code takes the result from the process and either displays error messages or an alert. I'm using
apex.message.alert
instead ofapex.message.showPageSuccess
because the former supports a callback when the message is dismissed. When the message is dismissed,apex.navigation.redirect
takes the user to Google.
Here's what it should look like in the end:
I hope there's enough information here for you to understand what's going on. Let me know if you have any questions. You'll find the documentation for apex.navigation
and apex.message
here: https://apex.oracle.com/jsapi
P.S. Here's an example of what the PL/SQL code would look like using APEX_JSON.
declare
l_error_count pls_integer := 0;
l_result_obj clob;
begin
apex_json.initialize_clob_output;
apex_json.open_object();
apex_json.open_array('errors');
if :P17_FIRST_NAME is null
then
l_error_count := l_error_count + 1;
apex_json.open_object();
apex_json.write('pageItem', 'P17_FIRST_NAME');
apex_json.write('message', 'First Name is required.');
apex_json.close_object();
end if;
if :P17_LAST_NAME is null
then
l_error_count := l_error_count + 1;
apex_json.open_object();
apex_json.write('pageItem', 'P17_LAST_NAME');
apex_json.write('message', 'Last Name is required.');
apex_json.close_object();
end if;
apex_json.close_array();
if l_error_count > 0
then
apex_json.write('status', 'error');
apex_json.close_object();
:P17_RESULT := apex_json.get_clob_output();
apex_json.free_output;
return;
end if;
null; -- do "success" processing here
apex_json.write('status', 'success');
apex_json.write('message', 'Hi ' || :P17_LAST_NAME || ' ' || :P17_LAST_NAME ||
'! You will now be redirected to Google.');
apex_json.close_object();
:P17_RESULT := apex_json.get_clob_output();
apex_json.free_output;
end;
Related Topics
React-Native: Application Has Not Been Registered Error
How to Check If a Textbox Is Empty Using JavaScript
How to Convert Gmt Time to Ist Time in JavaScript
How to Convert Raw Mp3 Binary into Blob Url and Play It in Audio Tag
Keep Selected Dropdown Result After Refreshing Page, Jquery
How to Hide Select Options With Javascript (Cross Browser)
How to Change Colour of Text Based on Its Value When a Page Initially Loads
Regular Expression to Check Only One Decimal Point
How to Manipulate a Select Options Based on Another Select Option in HTML
How to Have Multiple Buttons of Same Id Value and When Click on Any Button the Pop-Up Should Come
Random Numbers Between 1 and 50; 50 Times
Postman: How to Check Whether the Field Is Returning Null in the Postman Automation
Pass Dynamic Object in Onclick - Javascript/Jquery
How to Add Node Module to Angular Project If Is Not Schematics Enabled
Changing the Value of Json Object's Key, Changes Other Values Also
How to Vertically and Horizontally Center a Component in React