17.5 Understanding Application Processes

This section describes how to create and manage application processes. Application processes are blocks of PL/SQL logic that are set to run at specific points using processes from multiple pages of an application. By default, application processes execute at the same point for every page in the application. However, you can apply conditions for specific pages to control when the process executes.

Tip:

To learn more about execution behavior in the case of a validation error, see "What Happens When a Validation Fails?."

17.5.1 About On Demand Application Processes

An On Demand process is special type of application process which has a Process Point of On Demand and executes when called from a page-level On Demand process or from an Ajax call from the browser. On Demand processes are useful when you have PL/SQL logic that you would like to run from different execution points across multiple pages.

On Demand processes should typically be created on a page and not at the application-level. On Demand processes created at the application-level are created with an initial authorization scheme of Must Not Be Public User. This prohibits the processes being invoked from users in unauthenticated sessions.

17.5.2 About Application Processes that Execute On New Instance

Typically an application process runs at the same point across multiple pages in an application. Processes having a Process Point of On New Instance are the exception. These types of processes are useful when you only need to retrieve information once within a user's session. For example, if the application items do not depend on the logged in user, you can initialize them using the Process Point On New Instance. To look up information that depends on the user, you can also use After Authentication.

If you configure applications to share the same session by setting the same cookie name in the authentication scheme, On New Instance and After Login, the application processes fire whenever Oracle Application Express first processes a request for the application (that is, On New Instance), or processes a request of an authenticated user for the application (that is, After Authentication).

17.5.3 About Running an On Demand Process from a Page Request

You can have a page request run an On Demand process by using the following syntax:

f?p=application_id:page_id:session:APPLICATION_PROCESS=process_id

Where:

  • application_id is the application ID or alphanumeric alias

  • page_id is the page number or alphanumeric alias

  • session is the session ID

  • APPLICATION_PROCESS=process_id is the keyword APPLICATION_PROCESS= followed by either the process ID or an alphanumeric name of an application-level process having a Process Point of On Demand

When you use this syntax, the Application Express engine recognizes the request and processes it using the following rules:

  • The page number in the URL can be the current page number or alias. A page number or alias is required in the request only as a syntactic placeholder because no specific page is accessed for this type of request.

  • The process authorization scheme, the application's authorization scheme, and the process conditions are supported.

  • Session state (that is, item names and values) may be set in the URL, but clear cache options are ignored.

  • Any failures of authentication, authorization, or process conditions do not result in visible error messages or other indicators of such failures and most often result in a blank page being displayed. Note that if you are logged in to Application Builder as a developer, an error messages displays.

  • Specifying the process by name locates the first process with the specified (case-preserved) name.

17.5.4 Application Process Example

A shopping cart application is a good example of when you might use an application process. For example, to display the contents of a user's shopping cart with each page view, you create a region on page zero of your application that displays the values of the application-level items TOTAL_CART_ITEMS and TOTAL_PURCHASE_PRICE.

Instead of writing a process for each page to set the values of TOTAL_CART_ITEMS and TOTAL_PURCHASE_PRICE, you could write an application process of type On Load: Before Header to compute these values. Then, the Application Express engine would execute the process on each page as it renders the application. As a result, each page, would display the most current values for TOTAL_CART_ITEMS and TOTAL_PURCHASE_PRICE.

17.5.5 Creating an Application Process

To create an application process:

  1. Navigate to the Shared Components page:

    1. On the Workspace home page, click Application Builder.

    2. Select an application.

    3. On the Application home page, click Shared Components.

      The Shared Components page appears.

  2. Under Application Logic, select Application Processes.

    The Application Processes page appears.

  3. Click Create.

  4. For Identification:

    1. Name - Enter a name for the application process.

    2. Sequence - Specify the sequence number for this process. The sequence number determines the order in which the process is evaluated relative to other processes that execute at the same point.

    3. Point - Identify the point during the processing of each page in the application that this process would run. Note the option, On Demand, only runs when requested by a page process.

    4. Click Next.

  5. For Source:

    1. PL/SQL code - Enter the PL/SQL code of your application process. The code will automatically be wrapped with a Begin and End;.

    2. Error Message - Enter the error message that displays if the process raises an error. See "Creating Application Process Error Messages."

    3. Click Next.

  6. For Conditionality:

    1. Condition Type - Select a condition type that must be met in order for this process to execute.

    2. Expression 1 and Expression 2 - Use these attributes to conditionally control whether the process executes. Enter values in this attribute based on the specific condition type you select. The process executes if the specified condition is met.

    3. Click Create Process.

17.5.6 Editing Application Process Attributes

To edit an existing page process:

  1. Navigate to the Shared Components page:

    1. On the Workspace home page, click Application Builder.

    2. Select an application.

    3. On the Application home page, click Shared Components.

      The Shared Components page appears.

  2. Under Logic, select Application Processes.

    The Application Processes page appears.

  3. Click the process name.

  4. Edit the appropriate attributes. For more information, see field-level Help.

  5. Click Apply Changes.

17.5.7 Creating Application Process Error Messages

If a process raises an error, you can define an error messages that displays to the user. How the error message displays depends upon the processing point. For processes with a processing point of On Submit - Before Computation and Validations or On Submit - After Computations and Validations, you can specify whether the error message displays inline on the current page (the default) or on a separate page. For all other application processes, error messages display on a separate error page.

To create an application process error message:

  1. Access the application process attributes. See "Editing Application Process Attributes."

  2. Edit the following attributes:

    1. Source, Process Error Message - Enter the message that displays when an unhandled exception is raised.

    2. Error message display location - Applies to processes with a processing point of On Submit - Before Computation and Validations or On Submit - After Computations and Validations, you can specify where the error message displays.

      Select one of the following:

      • Inline in Notification - Error displays inline on the page in the "notification" area (defined as part of the page template).

      • On Error Page - Error displays on a separate error page.

        If the application contains a manually created tabular form (using APEX_ITEM calls in the SQL statement), select On Error Page. Otherwise, changes made by the user are discarded when the page is re-rendered. When errors are displayed on a separate error page, the user can use the browser's Back button to preserve the entered values.

  3. Click Apply Changes.

17.5.8 Viewing the Application Processes History Report

The Application Process History report displays recent modifications made to application processes.

To access application processes History reports:

  1. Navigate to the Shared Components page:

    1. On the Workspace home page, click Application Builder.

    2. Select an application.

    3. On the Application home page, click Shared Components.

      The Shared Components page appears.

  2. Under Logic, select Application Processes.

    The Application Processes page appears.

  3. Select the History tab at the top of the page.

  4. You can customize the appearance the page using the Search bar at the top of the page. Available controls include:

    • Select columns to search - Resembles a magnifying glass. Click this icon to narrow your search. To search all columns, select All Columns.

    • Text area - Enter case insensitive search criteria (wildcard characters are implied) to search for a process by name and click Go.

    • Go button - Executes a search or applies a filter.

    • Actions menu - Use the Actions menu to customize the report view. See "About the Actions Menu."