16.10 Using Shortcuts

Use shortcuts to avoid repetitive coding of HTML or PL/SQL functions.

16.10.1 What is a Shortcut?

Learn about shortcuts and when to use them.

Use a shortcut to define frequently used code once and then reference it in many places thus reducing code redundancy. For example, you can create a shortcut to define a page control such as a button, HTML text, a PL/SQL procedure, or HTML.

You can use a shortcut within the following locations:

  • The Region Source attribute of regions defined as HTML Text (with shortcuts).
  • Region Header and Footer Text attribute.
  • Item Label attributes, Pre Element Text, Post Element Text, and Default Value attribute.
  • Region Templates attributes.

Referencing a Shortcut

Once you define a shortcut, you can invoke it using specific syntax unique to the location in which the shortcut is used.

You reference shortcuts using the following syntax:

"MY_SHORTCUT"

The shortcut name must be capitalized and enclosed in quotation marks.

16.10.2 Supported Shortcut Types

Oracle APEX supports six types of shortcuts.

When you create a shortcut you select a shortcut type. Supported shortcut types include:

  • PL/SQL Function Body
  • HTML Text
  • HTML Text with Escaped Special Characters
  • Image
  • Text with JavaScript Escaped Single Quotes
  • Message
  • Message with JavaScript Escaped Special Quotes

Text with JavaScript Escaped Single Quotes

Use this type of shortcut to reference a shortcut inside of a JavaScript literal string. This shortcut defines a text string. When the shortcut is referenced, it escapes the single quotation marks required for JavaScript.

Message

Use this type of shortcut to reference a translatable message at runtime. Since this shortcut does not have a shortcut body, the name of the shortcut must match the corresponding message name. At runtime, the name of the shortcut expands to the text of the translatable message for the current language.

Message with JavaScript Escaped Single Quotes

Use this type of shortcut to reference a shortcut inside of JavaScript literal string and reference a translatable message at runtime.

16.10.3 Defining a Shortcut from Scratch

Define a shortcut on the Shortcuts page.

To define a shortcut:

  1. Navigate to the Shared Components page:
    1. On the Workspace home page, click App Builder.
    2. Select an application.
    3. On the Application home page, click Shared Components.

      The Shared Components page appears.

  2. Under Other Components, select Shortcuts.
  3. Click Create.
  4. For Create Shortcut, select From Scratch and click Next.
  5. On Shortcut Attributes:
    1. Name - Enter the name by which the shortcut will be referenced.
    2. Type - Select a shortcut type. Options include:
      • PL/SQL Function Body

      • HTML Text

      • HTML Text with Escaped Special Characters

      • Image

      • Text with JavaScript Escaped Single Quotes

      • Message

      • Message with JavaScript Escaped Special Quotes

    3. Shortcut - Enter the text of the shortcut. The shortcut must be less then 30,000 characters in length.
    4. Error Text - Enter the text to display if an error should occur during the processing of a shortcut.
    5. Build Option - Select a build option for this component.
  6. Click Create.

    New shortcuts are added to the Shortcuts page (also referred to as the Shortcut repository).

16.10.4 Editing Existing Shortcuts

Once you create a shortcut, you can alter it by editing attributes on the Edit Shortcut page.

To edit an existing shortcut:

  1. Navigate to the Shared Components page:
    1. On the Workspace home page, click App Builder.
    2. Select an application.
    3. On the Application home page, click Shared Components.

      The Shared Components page appears.

  2. Under Other Components, select Shortcuts.
  3. Select a shortcut.

    The Edit Shortcut page appears.

  4. Edit the attributes.

    To learn more about an attribute, see field-level Help.

  5. Click Apply Changes.

16.10.5 Copying an Existing Shortcut

Copy existing shortcuts from the Shortcut repository.

To copy an existing shortcut:

  1. Navigate to the Shared Components page:
    1. On the Workspace home page, click App Builder.
    2. Select an application.
    3. On the Application home page, click Shared Components.

      The Shared Components page appears.

  2. Under Other Components, select Shortcuts.
    The Shortcuts page appears. You can copy an existing shortcut from the Create Shortcut Wizard or by clicking Copy icon in report view.
  3. To copy an existing shortcut the Create Shortcut Wizard:
    1. On the Shortcut page, click Create.
    2. On Creation Method, select As a Copy of an Existing Shortcut and click Next.
    3. From Copy From Application, select the application you want to copy shortcuts from and click Next.
    4. Copy From Application - Select the application from which you want to copy shortcuts.
    5. New Shortcuts:
      • To Name - Optionally enter the new shortcut name.
      • Copy - Select an action:
        • Yes - Copy the shortcut.
        • No - Do not copy this shortcut.
        • Copy and Subscribe - Copy and subscribe to this shortcut. Subscribing to a shortcut copies it to application and sets the plug-in master reference.
    6. Click Copy Shortcut.
  4. To copy an existing shortcut by clicking the Copy icon:
    1. On the Shortcut page verify report view is enabled.
    2. In the Copy column, click Copy.
    3. Copy Shortcut - Select the shortcut to copy.
    4. Shortcut Name - Enter the new name of the shortcut to be copied.
    5. Click Copy.

16.10.6 Copying or Subscribing to a Shortcut

Copy a shortcuts from the current application or from another applications. When copying a shortcut from another app, you can also subscribe to it.

Tip:

Subscriptions enable developers to reuse shared components across several applications in a workspace. To learn more about subscriptions, see Using Shared Component Subscriptions.

To copy or subscribe to a shortcut:

  1. Navigate to the Shared Components page:
    1. On the Workspace home page, click App Builder.
    2. Select an application.
    3. On the Application home page, click Shared Components.

      The Shared Components page appears.

  2. Under Other Components, click Shortcuts.

    The Shortcuts page appears. Note that the report includes the following columns: Subscribed From, Subscription Status, and Subscribers.

  3. From the Tasks list, click Copy from another app.
  4. Copy From:
    1. Copy From Application - Select an application from which to copy.
    2. Click Next.
  5. New Shortcuts:
    1. To Name - Optionally enter the new shortcut name.
    2. Copy - Select an action:
      • Yes - Copy the shortcut.
      • No - Do not copy this shortcut.
      • Copy and Subscribe - Copy and subscribe to this shortcut. Subscribing to a shortcut copies it to application and sets the plug-in master reference.
  6. Click Copy Shortcut.

16.10.7 Subscribing to a Shortcut

Subscribe to a shortcut on the Shortcuts, Edit page.

Subscriptions enable developers to reuse shared components across several applications in a workspace. To learn more about shared component subscriptions, see Using Shared Component Subscriptions.

Tip:

You can also subscribe to a shortcut by copying it and then subscribing. See Copying or Subscribing to a Shortcut.

To subscribe to a shortcut:

  1. Navigate to the Shared Components page:
    1. On the Workspace home page, click App Builder.
    2. Select an application.
    3. On the Application home page, click Shared Components.

      The Shared Components page appears.

  2. Under Other Components, click Shortcuts.

    The Shortcuts page appears. Note that the report includes the following columns: Subscribed From, Subscription Status, and Subscribers.

  3. Select a shortcut.
    The Shortcuts, Edit page appears.
  4. To subscribe to a shortcut:
    1. Find the Subscription region.
    2. Subscription, Subscribe From - Select a master shortcut to subscribe to and click Apply Changes.
    3. Confirm your selection and click Subscribe.

      The subscribed component is automatically refreshed from the selected master.

  5. To refresh a shortcut:
    1. Find the Subscription region.
    2. Subscription, Refresh Shortcut - If the shortcut is already subscribed, click Refresh Shortcut.
    3. Click Apply Changes.
  6. To unsubscribe from a shortcut:
    1. Find the Subscription region.
    2. Subscription, Unsubscribe - Click Unsubscribe.

16.10.8 Accessing Shortcut Reports

View the shortcut Subscription and History reports.

To access shortcut reports:

  1. Navigate to the Shared Components page:
    1. On the Workspace home page, click App Builder.
    2. Select an application.
    3. On the Application home page, click Shared Components.

      The Shared Components page appears.

  2. Under Other Components, select Shortcuts.
  3. Click one of the following tabs:
    • Subscription - Displays the Subscribed Shortcuts page which displays all subscribed shortcuts in your application.

    • History - Display the Shortcut History page which displays a history of recently changed shortcuts by date.

    Note:

    The Subscription and History tabs only appear after you create a shortcut.