Urlo
Urlo

Reputation: 21

Oracle APEX - how to raise an error in your own custom validation process without showing it on the error page

I am using Oracle Apex 19.2. I need to create a Form Page with many fields and many validations.

Instead of creating one Validation Routine for every field and check I want to put them all into one PL/SQL procedure and create Process Routine in APEX. Inside that pl/sql procedure I would perform all necessary checks and use apex_error.add_errorto add all errors into stack.

If there is at least one error I want to break procedure execution and show it on the page. The problem is that the procedure completes always successfully so no error is displayed. I tried raise_application_error but my custom error is also visible on error page.

The same applies when rising apex_application.e_stop_apex_engine - apart from my custom validations there is also ORA-20876 error from apex_application.stop_apex_engine.

Is there any way I could either break procedure execution without raising an error or ignore somehow the error I raise to break it?

Apex error

Upvotes: 0

Views: 4132

Answers (1)

Urlo
Urlo

Reputation: 21

Problem solved.

I defined my PL/SQL procedure as an APEX Process routine. Instead of that, I should have done it as an APEX Validation. It looks like APEX carries out all validations and then, even if they all went ok, it checks error stack and does not proceed with processing if there is any error. Below steps how to achieve it.

  1. Define a new APEX Validation with Validation Type = PL/SQL Function Body (returning Boolean)
  2. Here starts the tricky part - in the PL/SQL code field you put your PL/SQL procedure and you always return true. It looks like:

your_plsql_package.your_procedure; return true;

  1. In the mandatory field Error Message you write whatever message you want - It will never be displayed on the error page.

And that is it. Instead of having dozens validations on the page you can have one procedure to rule them all :) However, it could be more developer friendly.

Upvotes: 2

Related Questions