APEX-AT-WORK no image

Using individual error/success messages in APEX

Von Tobias Arnhold 1.25.2009
There are several ways about how to use own error/success messages in APEX page processes. I want to show how to use the internal APEX process.

To create an own alert message in a page process use that syntax:

apex_application.g_print_success_message := '<span style="color:green">Data from ' || :P1_DATE || ' successfully updated</span>';

With that function you replace the text of the internal APEX Process Success Message.

PL/SQL process example with own dynamic messages:

begin
IF :P1_COMPUTER like 'PC%' THEN
INSERT INTO...;
COMMIT;
apex_application.g_print_success_message := '<span style="color:green">Computer created</span>';
ELSE
apex_application.g_print_success_message := '<span style="color:red">No valid computer name</span>';
END IF;
END;

Example with own alert messages for updateable reports in a page process:
(In this example we have an updateable report with time values like 'hh24:mi' = '06:30'. Every object needs to be checked via a function check_time before an update will be made. If the result is 0 then a error message should occur)

DECLARE
-- variables
v_error number;
BEGIN

FOR i IN 1 .. APEX_APPLICATION.g_f50.COUNT -- count number of rows in this report
LOOP
-- UPDATE procedure
CASE WHEN check_time(APEX_APPLICATION.g_f01(i)) = 0 THEN
apex_application.g_print_success_message := '<span style="color:red">Value ' || APEX_APPLICATION.g_f01(i) || ' is wrong.</span>';
ROLLBACK;
v_error := 1; EXIT;
ELSE
-- now an update command could be set
null;
END IF;
CASE WHEN check_time(APEX_APPLICATION.g_f02(i)) = 0 THEN
apex_application.g_print_success_message := '<span style="color:red">Value ' || APEX_APPLICATION.g_f02(i) || ' is wrong.</span>';
ROLLBACK;
v_error := 1; EXIT;
ELSE
-- now an update command could be set
null;
END IF;
CASE WHEN check_time(APEX_APPLICATION.g_f03(i)) = 0 THEN
apex_application.g_print_success_message := '<span style="color:red">Value ' || APEX_APPLICATION.g_f03(i) || ' is wrong.</span>';
ROLLBACK;
v_error := 1; EXIT;
ELSE
-- now an update command could be set
null;
END IF;
-- CASE ...
-- depending on the amount of columns
END CASE;
END LOOP;
-- no commit if error occurred, error only occur when validation went wrong
IF v_error is null then
COMMIT;
apex_application.g_print_success_message := '<span style="color:green">Updates successfully applied</span>';
END IF;
END;


That updateable process should just show how particular you can use these error/success messages in your application. With some javascript you could also change the object which is wrong. For example with a red object background.

Here are some posts to that topic in the Oracle forum:
http://forums.oracle.com/forums/thread.jspa?messageID=2717151
http://forums.oracle.com/forums/thread.jspa?messageID=2792051

Post Tags: