Directing Errors to an Alert
You might want to display errors automatically in an alert, by an On-Error trigger. The built-in functions in which return error information, like as ERROR_TEXT.can be used in the SET_ALERT_PROPERTY procedure, to construct the alert message for show.
Example
The subsequent user-named procedure can be called when the last form action was unsuccessful. A procedure fails the calling trigger and displays Error_Alert holding the error information.
PROCEDURE alert_on_failure IS
n NUMBER;
BEGIN
SET_ALERT_PROPERTY (
‘error_alert’,
ALERT_MESSAGE_TEXT,
ERROR_TYPE / / ‘-‘/ / TO_CHAR (ERROR_CODE)/ / ‘:’ / /-- error type declaration
ERROR_TEXT);
n := SHOW_ALERT (‘error_alert’);
END;
Alerts are another method for communicating with the operator. Since they show in a modal window and alerts gives an effectual way of drawing attention and forcing the operator to answer the message before processing can continue.
Whenever you required use alerts doing the following:
Setting alert properties at runtime
An alert might have to be displayed when the exit button on the data entry form is clicked. A functionality of this alert is the similar as all other alerts except the alert title and the message in the alert box must be different.
Alternatively of having two separate alerts, one for delete and one for exit. An Oracle forms permits these properties to be set at runtime. The message and the title can be changes depending on the button which is pressed permitting the use of one alert object to deal with multiple situations.
The subsequent are the steps to achieve this.
1.Open the product form in the forms builder. To locate the node labeled alerts and click on the navigator..Create option
2.In the properties window, set the subsequent properties:
Name : CONFIRM_ALERT
Alert style : Caution
Button 1 : Yes
Button 2 : No Default
Button : Button2
3.To show the alert the following trigger need to be added where it is needed.
Trigger Name : WHEN-BUTTON-PRESSED From : table Product
Function : button_palette item : pb_delete
Function : Display the alert message box before deleting a record.
Text : DECLARE
Chk_button number;
Begin
Go_block(‘product_master’);
set_alert_property(‘confirm_alert’,title,’Delete records’);
set_alert_property(‘confirm_alert’,alert_message_text,
‘do you really need to delete the record?’);
chk_button :=show_alert (‘alert_delete’);
if chk_button = alert_button1 then delete_record;
END;
endif;
Trigger name : WHEN-BUTTON-PRESSED form :product
Block : button_palette
Function : Quit the product form.
Text : DECLARE
Ans number;
BEGIN
If : system.form_status = ‘CHANGED’ then
Set_alert_property(‘confirm_alert’,title,’save changes’);
Set_alert_property(‘confirm_alert’,alert_message_text,
‘would you like to make modification permanent’);
ans : = Show_alert(‘confirm_alert’);
if ans = alert_button1 then
commit_form;
End if;
End if;
Exit_form(No_commit);
END;