Thursday, June 25, 2020

Show custom error message against database constraint in oracle apex

In oracle apex application, when an end user face an error on constraint (such as primary key, foreign key, unique key, check etc.) of database then user see the error message that defined on database. Most of the time that messages are not clear to end user. Sometimes error raises like it.
 

On this point, oracle apex has a great error handling feature to show our customize message to end user. For generating customized message, follow the following steps. It's very simple.

Firstly, you have to create a table. Here is the table script for you help.
CREATE TABLE  CONSTRAINT_LOOKUP 
   (CONSTRAINT_NAME VARCHAR2(30), 
	MESSAGE VARCHAR2(4000) NOT NULL ENABLE, 
	 PRIMARY KEY (CONSTRAINT_NAME) ENABLE
   );
Then create a function on your schema. You can just copy and paste function code from here.
CREATE OR REPLACE FUNCTION apex_error_handling_example (
   p_error IN apex_error.t_error)
   RETURN apex_error.t_error_result
IS
   l_result            apex_error.t_error_result;
   l_reference_id      NUMBER;
   l_constraint_name   VARCHAR2 (255);
BEGIN
   l_result := apex_error.init_error_result (p_error => p_error);

   IF p_error.is_internal_error
   THEN
      IF NOT p_error.is_common_runtime_error
      THEN
         -- Change the message to the generic error message which doesn't expose
         -- any sensitive information.
         l_result.MESSAGE :=
               'An unexpected internal application error has occurred. '
            || 'Please get in contact with XXX and provide '
            || 'reference# '
            || TO_CHAR (l_reference_id, '999G999G999G990')
            || ' for further investigation.';
         l_result.additional_info := NULL;
      END IF;
   ELSE
      l_result.display_location :=
         CASE
            WHEN l_result.display_location = apex_error.c_on_error_page
            THEN
               apex_error.c_inline_in_notification
            ELSE
               l_result.display_location
         END;

      IF p_error.ora_sqlcode IN (-1, -2091, -2290, -2291, -2292)
      THEN
         l_constraint_name :=
            apex_error.extract_constraint_name (p_error => p_error);

         BEGIN
            SELECT MESSAGE
              INTO l_result.MESSAGE
              FROM constraint_lookup
             WHERE constraint_name = l_constraint_name;
         EXCEPTION
            WHEN NO_DATA_FOUND
            THEN
               NULL;  
         END;
      END IF;

      IF     p_error.ora_sqlcode IS NOT NULL
         AND l_result.MESSAGE = p_error.MESSAGE
      THEN
         l_result.MESSAGE :=
            apex_error.get_first_ora_error_text (p_error => p_error);
      END IF;

      IF l_result.page_item_name IS NULL AND l_result.column_alias IS NULL
      THEN
         apex_error.auto_set_associated_item (p_error          => p_error,
                                              p_error_result   => l_result);
      END IF;
   END IF;

   RETURN l_result;
END apex_error_handling_example;
After then go to Shared Component / Application Definition Attributes / Error Handling section and place your function name at Error Handling Function field.

 
Finally, insert your message against constraint of database on CONSTRAINT_LOOKUP table.
NB: Here OID and SIDPK is the constraint name of database.

Now go to application and face the constraint error again see your customized message. For enhancing your error handling follow APEX_ERROR API.

Think it helps you. As always I am here to help you. Enjoy!

Sunday, May 10, 2020

How to expand navigation menu on hover in oracle apex

Oracle Apex application navigation menu has two types of position one is Top and another is Side. If your settings are like this image then after login at your application, navigation menu would be collapsed with icon because Collapse Mode is Icon(Default). It will expand after clicking the navigation icon from navigation menu.

How to expand navigation menu on hover
How to expand navigation menu on hover
If you want to expand your navigation menu on hover (when you mouse pointer will come) then follow the simple steps of this video.


Click the Download link to get the code that are used in this video.


Think it helps you. Good luck.

Friday, May 8, 2020

What happened on 20.1 API references in oracle apex

Slit your string with APEX_STRING_UTL

Think you have a large text phrase and now you have to separate web addresses or email addresses or links or specific phrases from here. What you will do now?

Don't worry! In new release 20.1 of Apex API reference introduce APEX_STRING_UTL as extension of APEX_STRING to do such complex task easily. APEX_STRING_UTL has the following functions:
  1. REPLACE_WHITESPACE Function
  2. FIND_FILE_EXTENSION Function
  3. FIND_PHRASE Function
  4. FIND_PHRASES Function
  5. FIND_EMAIL_ADDRESSES Function
  6. FIND_EMAIL_FROM Function
  7. FIND_EMAIL_SUBJECT Function
  8. FIND_TAGS Function
  9. FIND_LINKS Function
  10. GET_DOMAIN Function
  11. FIND_IDENTIFIERS Function
  12. TO_DISPLAY_FILESIZE Function
  13. TO_SLUG Function
Example 1:
select APEX_STRING_UTIL.TO_DISPLAY_FILESIZE(13312312) from dual;
-> 12.7MB
Example 2:
select APEX_STRING_UTIL.FIND_FILE_EXTENSION('foo.xlsx') from dual
-> xlsx
There are very effective functions in APEX_STRING_UTL are waiting for you.

Manage Interactive Grid with APEX_IG

This is also brand new API reference for Oracle Apex developers just like APEX_IR. By this package you will be able to add filter, delete saved report as well as clear or reset the IG report. APEX_IG has the following procedures and functions:
  1. ADD_FILTER Procedure Signature 1
  2. ADD_FILTER Procedure Signature 2
  3. CHANGE_REPORT_OWNER Procedure
  4. CLEAR_REPORT Procedure Signature 1
  5. CLEAR_REPORT Procedure Signature 2
  6. DELETE_REPORT Procedure
  7. GET_LAST_VIEWED_REPORT_ID Function
  8. RESET_REPORT Procedure Signature 1
  9. RESET_REPORT Procedure Signature 2
Others update at 20.1

APEX_AUTHENTICATION is updated in this release with new PERSISTENT_COOKIES_ENABLED function and update of SEND_LOGIN_USERNAME_COOKIE.

APEX_JSON has added new function GET_CLOB_OUTPUT for returning temporary CLOB.

APEX_INSTANCE_ADMIN add some parameters to get and set more control on workspace, instance, password and admin password. Here is the following parameters.
  1. WORKSPACE_NAME_USER_COOKIE
  2. PASSWORD_NOT_LIKE_USERNAME
  3. PASSWORD_NOT_LIKE_WORDS
  4. PASSWORD_NOT_LIKE_WS_NAME
  5. PASSWORD_ONE_ALPHA
  6. PASSWORD_ONE_LOWER_CASE
  7. PASSWORD_ONE_NUMERIC
  8. PASSWORD_ONE_PUNCTUATION
  9. PASSWORD_ONE_UPPER_CASE
  10. SERVICE_ADMIN_PASSWORD_MIN_LENGTH
  11. SERVICE_ADMIN_PASSWORD_NEW_DIFFERS_BY
  12. SERVICE_ADMIN_PASSWORD_ONE_ALPHA
  13. SERVICE_ADMIN_PASSWORD_ONE_NUMERIC
  14. SERVICE_ADMIN_PASSWORD_ONE_PUNCTUATION
  15. SERVICE_ADMIN_PASSWORD_ONE_UPPER_CASE
  16. SERVICE_ADMIN_PASSWORD_ONE_LOWER_CASE
  17. SERVICE_ADMIN_PASSWORD_NOT_LIKE_USERNAME
  18. SERVICE_ADMIN_PASSWORD_NOT_LIKE_WS_NAME
  19. SERVICE_ADMIN_PASSWORD_NOT_LIKE_WORDS
Deprecated and desupported at 20.1

You have to use OAUTH_AUTHENTICATE_CREDENTIAL intead of OAUTH_AUTHENTICATE Procedure Signature 2. Because OAUTH_AUTHENTICATE Procedure Signature 2 is deprecated from 20.1.

NB: You need minimum 20.1 version of Oracle Apex to run these API references. For more you can visit API documentation.

Think its help you. Good Luck.