Monday, February 24, 2014

APEX Shortcuts


The other day I was dabbling around in APEX and noticed a link for Shortcuts in the Shared Components section.



I’ve never used Shortcuts before (let along knew about them) so I tried it out. To start here’s how Shortcuts are described (as copied from APEX screen):

Shortcuts are a repository of shared static or dynamic HTML. Shortcuts are substitution strings that are expanded using the syntax: "SHORTCUT_NAME". Shortcuts are used in the following locations:

  • Region Source for regions of type HTML_WITH_SHORTCUTS
  • Region Templates, Region Headers & Footers
  • Item Labels
  • Item Default Value
  • Item Post Element Text
  • Item Help Text
  • HTML Header of a page

Creating shortcuts on page item labels and page item post element text attributes can include the following substitution strings: 
#CURRENT_FORM_ELEMENT# 
#CURRENT_ITEM_ID# 
#CURRENT_ITEM_NAME# 
#CURRENT_ITEM_HELP_TEXT#

To reference Shortcuts you need to use the “shortcutname” syntax (quotes included). Since they are wrapped in quotes and could conflict with regular text I strong recommend using a naming scheme such as SC_NAME.

Note: I previously wrote an article about the different ways to reference APEX variables. I have updated it to include Shortcuts. The article is available here.

Shortcuts can either be statically defined or reference a PL/SQL function. It’s important to note that if you do call a PL/SQL function it will execute the code each time the Shortcut is referenced. For example, if you have the same Shortcut in three different regions on a page it’ll call the function three times. This may be a good or bad thing depending on how you use it.

Though I haven’t found an immediate need for Shortcuts I think there could be some situations where it can come in handy for labels and templates especially since it allows you to reference a function which can dynamically generate content.

4 comments:

  1. The only use I've found is producing dynamic quick picks (prior to the plugin)

    ie - call pl/sql to generate list of anchors

    ReplyDelete
  2. (I thought I posted a response, but my phone must have decided not to process it properly)

    I've used shortcuts in the past to render a dynamic list of quick pick options - prior to the advent of a plug-in.

    ReplyDelete
  3. Another use for shortcuts I have used in the past is for dynamic labels. The labels were defined in a table and updatable by the application administrator.

    ReplyDelete
  4. I use shortcuts to display instructions (Region type: "HTML Text (with shortcuts)" and help text for items. I find them very useful because when you translate an application, you just translate the shortcut name (example : "DURATION_HELP_EN" to "DURATION_HELP_FR"). You create one shortcut for your primary language and another for each translation. You never loose your translations because they are in the shortcuts. Otherwise you loose your translated text each time you make a single modification to the text in your primary language.

    ReplyDelete