How to show a database trigger error message as a notification on a page

I have a database with database triggers to ensure data integrity.
If an insert or update does not comply to all the business rules, a database triggers raises an exception. When using Apex this exception is caught in the Error Screen, a separate screen, where the whole error stack is displayed.
Does anyone know a way to display only the error in RAISE_APPLICATION_ERROR as a notification in the screen from which the transaction was initiated?
Dik Dral

Well, having had so little response, i had to figure it out myself ;-)
Using Patrick Wolff's ideas from ApexLib I 'invented' a solution for my problem, that I would like to contribute to the community. I hope that it will come out a bit nicely formatted:
Apex: Show Database Error Message in calling form
The purpose is to show a neat error message in the notification area of the calling form.
Default Apex show the whole error stack raised by a DB trigger in a separate error page.
With acknowledgement to Patrick Wolf, I lent parts of his ApexLIB code to create this solution.
<br./>
Assumptions
<ul><li>The error message is raised from a DB trigger using RAISE_APPLICATION_ERROR(-20000,’errormessagetext’).</li>
<li>The relevant part of the error stack is contained within the strings ‘ORA-20000’ and the next ‘ORA-‘-string, i.e. if the error stack is ‘ORA-20000 Value should not be null ORA-6502 …’, than the relevant string is ‘Value should not be null’ .</li>
<li>Cookies are enabled on the browser of the user </li>
</ul>
Explanation
The solution relies heavily on the use of Javascript. On the template of the error page Javascript is added to identify the error stack and to extract the relevant error message. This message is written to a cookie, and then the control is passed back to the calling page (equal to pushing the Back button).
In the calling page a Javascript onLoad process is added. This process determines whether an error message has been written to a cookie. If so the error message is formatted as an error and written to the notification area.
Implementation
The solution redefines two template pages, the two level tab (default page template) and the one level tab (error page template).
Javascript is added to implement the solution. This Javascript is contained in a small library errorHandling.js:
<pre>
var vIndicator = "ApexErrorStack=";
function writeMessage(vMessage)
{       document.cookie = vIndicator+vMessage+';';
function readMessage()
{ var vCookieList = document.cookie;
var vErrorStack = null;
var vStart = null;
var vEnd = null;
var vPos = null;
vPos = vCookieList.indexOf(vIndicator);
// No cookie found?
if (vPos == -1) return("empty");
vStart = vPos + vIndicator.length;
vEnd = vCookieList.indexOf(";", vStart);
if (vEnd == -1) vEnd = vCookieList.length;
vErrorStack = vCookieList.substring(vStart, vEnd);
vErrorStack = decodeURIComponent(vErrorStack);
// remove the cookie
document.cookie = vIndicator+"; max-age=0";
return(vErrorStack);
function getElementsByClass2(searchClass,node,tag)
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = newRegExp('(^|\\s)'+searchClass+'(\\s|$)');
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els.className) ) {
classElements[j] = els[i];
j++;
return classElements;
function processErrorText()
var errorElements = new Array();
errorElements = getElementsByClass2("ErrorPageMessage",document,"div");
if (errorElements.length > 0 )
{ errorText = errorElements[0].innerHTML;
errorText = errorText.substr(errorText.indexOf("ORA-20000")+ 11);
errorText = errorText.substr(0,errorText.indexOf("ORA")-1);
// errorElements[0].innerHTML = errorText;
writeMessage(errorText);
function show_message()
{ var vCookieList = document.cookie;
var vErrorStack = null;
var vErrorName = null;
var vErrorMessage = null;
var vStart = null;
var vEnd = null;
var vPos = null;
// get errorStack
vErrorStack = readMessage();
if (vErrorStack == -1) return;
// search for our message section (eg. t7Messages)
var notificationArea = document.getElementById("notification");
if (notificationArea != null)
{ notificationArea.innerHTML = '<div class="t12notification">1 error has occurred<ul class="htmldbUlErr"><li>' + vErrorStack + '</li></ul>'; }
else
{ alert(vErrorStack); }
</pre>
This code is loaded as a static file in Application Express (no application associated).
In both templates a reference to this code is added in the Definition Header section:
<pre>
<script src="#WORKSPACE_IMAGES#errorHandling.js" type="text/javascript"></script>
</pre>
This library is called from the two level tab to show the error message (if any) in het onLoad event of the body tag.
<body onLoad="javascript:show_message();">#FORM_OPEN#
This code checks whether a message has been written to a cookie and if found displays the message in the notification area.
In the error template page the Error section has the content:
<script language="javascript">
processErrorText();
window.history.go(-1);
</script>
Back
The call to processErrorText() looks for the error message, extracts the relevant part of it (between ‘ORA-20000’ and the next ‘ORA-‘), writes it to a cookie and returns to the previous screen.
The link to the previous page is added should an error in the Javascript occur. It provides the user with a path back to the application.
With these actions taken, the error messages issued from triggers are shown in the notification area of the form the user has entered his data in.
The need for database driven messaging
In some cases the need exists to process error messages in the database before presenting them to the user. This is the case, when the triggers return message codes, associated to error messages in a message table.
This can be done by using a special Error Message Processing page in Apex.
The error message page extracts the error message, redirecting to the Error Message Processing page with the error message as a parameter. In the EMP page a PL/SQL function can be called with the message as a parameter. This function returns the right message, which is written to a cookie using dynamically generated Javascript from PL/SQL. Than the contol is given back to the calling form.
The redirect is implemented by location.replace, so that the error message page does not exist within the browsing history. The normal history(-1) will return to the calling page.
Implementation of database driven messaging
The solution redefines two template pages, the two level tab (default page template) and the one level tab (error page template).
Javascript is added to implement the solution. This Javascript is contained in a small library errorHandling.js already listed in a previous paragraph.
In both templates a reference to this code is added in the Definition Header section:
<script src="#WORKSPACE_IMAGES#errorHandling.js" type="text/javascript"></script>
This library is called from the two level tab to show the error message (if any) in het onLoad event of the body tag.
<body onLoad="javascript:show_message();">#FORM_OPEN#
This code checks whether a message has been written to a cookie and if found displays the message in the notification area.
In the error template page the Error section has the content:
<script language="Javascript">
var errorText = null;
function redirect2oracle()
{ window.location.replace("f?p=&APP_ID:500:&APP_SESSION.::::P500_MESSAGE:"+errorText); }
function getError()
{ errorText = processErrorText(); }
getError();
redirect2oracle();
</script>
Go to Error Message Porcessing Page
Back to form
The call to processErrorText() looks for the error message, extracts the relevant part of it (between ‘ORA-20000’ and the next ‘ORA-‘), writes it to a cookie.
Then the EPM-page (500) is called with the extracted message as parameter.
The link to the EPM page and the previous page is added should an error in the Javascript occur. It provides the user with a path back to the application.
We need to create an Error Message Porcessing Page.
Create a new page 500 with a empty HTML-region “Parameters”
Create an text-area P500_MESSAGE in this region
Create a PL/SQL region “Process Messages” with source:
convert_message(:P500_MESSAGE);
Create a PL/SQL procedure convert_message like this example, that reads messages from a message table. If not found, the actual input message is returned.
CREATE OR REPLACE procedure convert_message(i_message in varchar2) is
v_id number := null;
v_message varchar2(4000) := null;
function get_message (i_message in varchar2) return varchar2 is
v_return varchar2(4000) := null;
begin
select msg_text into v_return
from messages
where msg_code = upper(i_message);
return(v_return);
exception
when no_data_found then
return(i_message);
end;
begin
v_message := get_message(i_message);
// write the message for logging/debugging
htp.p('Boodschap='||v_message);
// write cookie and redirect to calling page
htp.p('<script language="Javascript">');
htp.p('document.cookie="ApexErrorStack='||v_message||';";');
htp.p('window.history.go(-1);');
htp.p('</script>');
// enter return link just in case
htp.p('Ga terug');
end;
Note: The way the message is converted is just an example
With these actions taken, the error messages issued from triggers are shown in the notification area of the form the user has entered his data in.
Message was edited by:
dickdral
null

Similar Messages

  • Show a insert trigger error message on a compiled form

    Good Morning
    Is there any way to get a oracle complied form to display a message
    from a trigger insert event.
    My problem is that we have proprietry oracle froms application (with compiled
    forms and no source code. I need to raise some sort of warning message
    from the form when certain condition occurs.
    I have tried using some code like below in the trigger
    but the dbms_output.put_line does not output anything
    nor the EXCEPTION
    DECLARE MY_ERROR exception;
    begin
    DBMS_OUTPUT.ENABLE;
    dbms_output.put_line('outputting this message');
    raise MY_ERROR;
    EXCEPTION
    WHEN others THEN Raise;
    END;
    thanks
    David Hills

    You don't need to get at the source code of the form. The example you gave will stop the execution of any process and you said it should happen for an insert event. So a Raise_Application_Error in a database trigger would be sufficient.
    Hopefully the vendor has put code in their on-error triggers which will cut the message out of a user-defined exception and display it as an alert (this is so much a better method than returning numbers to indicate success or type of failure). If not then the message will be rather ugly but it will at least get the job done.
    James.

  • Try to retrieve data from database got error message

    Try to retrieve data from database got error message *"java.lang.ArrayIndexOutOfBoundsException: 2*
    *     sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter(JdbcOdbcPreparedStatement.java:1023)*
    *     sun.jdbc.odbc.JdbcOdbcPreparedStatement.setDate(JdbcOdbcPreparedStatement.java:811)*
    *     guestbk.doGet(guestbk.java:32)*
    *     guestbk.doPost(guestbk.java:73)*
    *     javax.servlet.http.HttpServlet.service(HttpServlet.java:710)*
    *     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)"*
    I have used prepared statment
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd/MM/yy");
                java.util.Date dt = sdf.parse(str3);
                       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                       con=DriverManager.getConnection("jdbc:odbc:gbook");
                       //Statement stmt=con.createStatement();
    PreparedStatement ps = con.prepareStatement("SELECT * from gbook where emailid =? AND date =?");
    ps.setString(1,str1);
    ps.setString(2,str2);
    ps.setDate(3,new java.sql.Date(dt.getTime()));
    //ps.executeQuery();
                       //ResultSet rs=stmt.executeQuery("select * from gbook where emailid = str1");
                  ResultSet rs = ps.executeQuery();
                       out.println("<Html>");
                    out.println("<Head>");
                       out.println("<Title>GuestBook</Title>");
                       out.println("</Head>");
                       out.println("<Table border=1 align=center >");
                       out.println("<H4><B><center>Teacher's Lesson Plan</center></B></H4><BR>");
                       out.println("<TR><TD><b>Teacher Name</b></TD><TD><b>Class</b></TD></TR>");
               while(rs.next())
                        ctr++;
                        String email=rs.getString("emailid");
                        String cmt=rs.getString("comment");
                        out.println("<TR><TD>"+email+"</TD><TD>"+cmt+"</TD></TR>");
            }Please anybody help .

    PreparedStatement ps = con.prepareStatement("SELECT * from gbook where emailid =? AND date =?");
    ps.setString(1,str1);
    ps.setString(2,str2);
    ps.setDate(3,new java.sql.Date(dt.getTime()));Your SQL query has 2 placeholders but you try to set 3 values.
    And didn't you read the stack trace?
    guestbk.doGet(guestbk.java:32)You could've tracked down line 32 and seen what was there at that line.
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://www.catb.org/~esr/faqs/smart-questions.html
    ----------------------------------------------------------------

  • How to get rid of the error message we could not complete your iTunes store request?

    How to get rid of the error message we could not complete your iTunes store request?
    having this problem when trying to authorise an newly downloaded app in iTunes

    Based on the numerous posts regarding iTunes and the App Store, there appears to be an issue at Apple's end. Although Apple has not provided any indication on the cloud status page.
    Do not change your settings.
    Edit

  • How do I get rid of error message, "iTunes could not back up the iPad because an error occurred."

    During a recent syncing of my iPad and iTunes, I cancelled a sync during the backup step of the process.  Since then I whenever I sync the ipad I know get, "iTunes could not back up the iPad because an error occurred."
    I have reset my iPad and turned off the MacBook, still the message occurs.
    Can someone offer some advice on how to get rid of this error message?

    You can try deleting your backup. Launch Itunes on your Mac and go to iTunes>Preferences>Devices. Highlight the name of the iPad backup and select delete. Quit iTunes, restart your Mac and try to sync again.

  • How do I get past the error message Sign In Failed on my 2nd computer?

    How do I getr past the error message Sign In Failed on my 2nd computer? I have signed out, uninstalled, and reinstalled to no avail.

    So I thought: let's try the link Carolyn Samit suggested. So I got to Apple - Support - FaceTime to find information I already knew, about port forwarding I had already tried:
    443 (TCP)
    3478 through 3497 (UDP)
    5223 (TCP)
    16384 through 16387 (UDP)
    16393 through 16402 (UDP)
    What's the logic anyway of opening router ports that let my Wi-Fi devices through while refusing a LAN device? What have we got here? A firewall that only protects against cables?
    I guess Apple is too busy selling iPads to help a customer who's trying to use Apple software on an Apple machine.

  • How to  find out where sap error messages stored...

    How to  find out where sap error messages stored in our system.like sometime we will get a error message with message number.whr it will be stored and whch table it is?

    Hi,
    I also got the same message when that message no is not there
    E:SABAPDOCU:000 test 
    yours is S-type and message id ZY and message no 127
    127 is not there either change the no  or create the same
    Regards
    Shiva

  • How to find out where sap error messages stored in our system

    How to find out where sap error messages stored in our system.like sometime we will get a error message with message number.whr it will be stored and whch table it is?

    Are you interested in WDA messages ?
    The set a breakpoint in METHODS IN class CL_WDR_MESSAGE_MANAGER.
    Then use call stack (default desktop 2 in debugger) to see where message is added to message manager.
    regards
    phil

  • How fix Explorer 11 PDF Conversion Error Messages - used to work fine!

    Using Win7 and Explorer 11. Acrobat 9.5.xx PDF Reader/Creator.
    Works fine on one PC at home and other PC (same config and settings) gives error message "Could not access Acrobat Web Capture Facility".
    Tried repairing Acrobat 9.5.xx with same error results.
    Suggested solution so I can get back to creating PDFs of Websites??

    Not a reply. Screen shot of error message when trying to convert web page to PDF using Acrobat 9.5.5
    Any suggestions how to repair?
    /Mike

  • How do I fix an install error message 0x8007054f

    How do I fix an install error message 0x8007054f

    https://discussions.apple.com/thread/3029902?start=0&tstart=0
    old link may be broken new one right here
    http://support.microsoft.com/kb/946414
    Just wanted to make sure you understand that if you do have question, there are the odds someone already answered it, and it wasn't me.

  • I have been using CS6 for two years without incident.  Suddenly the Media Encoder stops working, showing APPCRASH and displaying error message about WatchFolder.dll - I tried uninstalling and re-installing to no avail - can anyone help

    I have been using CS6 for two years without incident.  Suddenly the Media Encoder stops working, showing APPCRASH and displaying error message about WatchFolder.dll - I tried uninstalling and re-installing to no avail - can anyone help?

    Hi Mylenium,
    Thanks for your response.
    Here is the error information showing up:
    Problem signature:
      Problem Event Name: APPCRASH
      Application Name: Adobe Media Encoder.exe
      Application Version: 6.0.0.382
      Application Timestamp: 4f62fcf1
      Fault Module Name: WatchFolder.dll
      Fault Module Version: 6.0.0.382
      Fault Module Timestamp: 4f62f37f
      Exception Code: c0000005
      Exception Offset: 0000000000007899
      OS Version: 6.1.7601.2.1.0.768.3
      Locale ID: 4105
      Additional Information 1: 9a62
      Additional Information 2: 9a620826d8ae4a2fa8b984b39290a503
      Additional Information 3: 1fb3
      Additional Information 4: 1fb304eee594288faeefbf1271b70d37
    I am using a PC Windows 7

  • Why is my iPhone 5c showing a borrowed blocks error message?

    My son's iPhone 5c is showing a borrowed nicks error message. What should I do?

    Sorry! A BORROWED BLOCKS message.

  • How to modify display label in error message raised from capi?

    How to modify display label in error message raised from capi?
    qms_transaction_mgt.process_rule_violation
    ( p_br_name => 'BR_PBR_DEL006'
    , p_msg_code => 'PMS-00417'
    , p_display_label => display_label
    , p_table_name => 'pan_project_members'
    , p_table_rowid => get_rowid
    regards,
    marcel

    When you mean which columns are displayed, this is actually quite easy.
    Display_label will display by default the unique key columns, or if no unique key exists, the primary key. To overrule this behaviour, you have to specify the columns you want to display by assigning them a 'descriptor sequence'.
    For example, to display the ename on EMP warnings, assign descriptor sequence 10 to the EMP.ENAME column and regenerate the CAPI package.
    Jeroen van Veldhuizen

  • How can I get past the error messages that keep popping up when I try to download Flash player?

    How can I get past the error messages that keep popping up every time I try to download anything?

    Hi
    Could you please let us know more about the error messages that you got?
    The following page has information on the error messages: http://helpx.adobe.com/content/help/en/flash-player/kb/installation-problems-flash-player- windows.html
    Thanks,
    Sunil

  • Did recent recommended update cause incompatibility with HP printer, causing error message and printer to print blank pages?

    did recent recommended update cause incompatibility with HP printer, causing error message and printer to print blank pages?

    Why not contact HP tech support for assistance since they make the printer. While on their site you can look for an updated printer driver. Otherwise, try deleting the current installed driver, reset the print system, then reinstall your printer's driver.
    Mac OS X- How to reset the printing system

Maybe you are looking for