Using Built-in Substitution Strings Tutorial – Part 2

Part one of this tutorial demonstrated the use of the apex_application API. This second part will build on this to look at other substitution strings that are available and how they can be used. The exercise below will create a simple “About” page that can be used for any APEX application. It is assumed that you have a workspace with the Sample Application installed as we will be building upon this application and it’s data structure.

The purpose of this tutorial is not to provide a list of substitution strings with their definitions, this can be found in the Oracle APEX help pages. These provide an easy reference to the different built-in substitution strings and the different ways they can be accessed.

Exercise 2 – Navigating back to the previous page

Often we want the user to be able to navigate back to the page they came from. Although we could use JavaScript to achieve this, this may not be possible if we also want to return values. One example is a simple search wizard: we have a person search wizard that is called from various places in the application and the user searches for a person on this page. When the person is selected the user is returned to the previous page and the id for the selected person is also returned so that the calling page is then in context of that person.

For this exercise we want to add an “About” page to the application that can be accessed from the Navigation Bar and returns the user back to the page they were previously on.

In the Application Builder:

  1. Select the Sample Application and click Create Page.
  2. Leave Blank Page selected and click Next.
  3. Give the page a name of “About”, do not use Breadcrumbs or Tabs and click through the wizard to Finish and create this page.
  4. Now click Edit Page and click to add a Region to this page.
  5. Click Next twice, accepting the Region is a normal HTML region, and set the name to be “About” and click Create.
  6. Now click to add a button to this Region.
  7. Click Next twice, confirming the button will be added to the About region and that you want to “Create a button in a region position.”
  8. Give the button a name and label of “OK” and click Next.
  9. Now click Next to navigate through the wizard, accepting all the default options, and finally select Create Button when available.
  10. Click to add a new item to this region.
  11. Click Next twice to create a Text item (note: in a real application you would create a hidden item instead).
  12. Set the item name to be P22_RETURN_PAGE, assuming your page is 22, and click Next to navigate through the wizard and create the Item.
  13. Now that you have an item to hold your returning page and a button to navigate back, you need to create a Branch. So click to create a new Branch.
  14. Click Next, then set the Page to be &P22_RETURN_PAGE. It’s very important that you remember the leading ampersand and the trailing full stop!
  15. Set the When Button Pressed field to be the OK button you’ve just created.
  16. Click the plus icon in the Navigation Bar region on your page to create a new entry in the Navigation Bar of your application.
  17. Set the Text to “About” and click Next.
  18. Set the page to be “22”, set Set these items to be P22_RETURN_PAGE and in the With these values type &APP_PAGE_ID.
  19. Now navigate back to your application and click Run Application, rather than running page 22.
  20. You should see an About link in your navigation bar. If you click this the Return Page field will display the page you were just on and the OK button will take you back to that page.

This exercise uses a couple of useful pieces of functionality. Firstly, the use of &P22_RETURN_PAGE. in the branch allows the branch on the page to be dynamic. Secondly, the use of the APP_PAGE_ID substitution string in the Navigation Bar link. This substitution string holds the page number that you are currently on and allows us to tell the About page where we want to return to.

Sara

Sara Blair is a freelance Oracle developer with over 10 years Oracle experience. She has been working with Oracle APEX for nearly 4 years since htmldb 1.5, and is available to hire through Silvercore Solutions.

5 Responses to “Using Built-in Substitution Strings Tutorial – Part 2”

  • Barry says:

    Sara,

    I work for a group that is just starting APEX development. These tutorials are very good. I share these with my fellow APEX developers and we enjoy these very much.

    Please keep up the good work.
    Barry

  • Dan says:

    Sara,

    In addition to using the branch, you could make the button a redirect instead of submit and put &P22_RETURN_PAGE. in the redirect page.

    Regards,
    Dan

  • toopran says:

    Sara,

    I have tried this on my workspace and it works well. Is there any way in which I could use ‘about’ only on desired page, rather on the navigation bar, as it appears on all the pages.

    thanks,
    Toopran

    • Sara Blair says:

      Hi Toopran

      In you application, if you go to shared components > navigation bar entries then select the about entry. Now scroll to the conditions section and here you can select a condition that when true will display the about link in the navigation bar. I would suggest that you could use the condition ‘Current Page is Defined Within Expression 1’ as you can then list the pages in Expression 1 that you want it to display on making sure the page numbers are comma delimited.

      Regards
      Sara

  • Bobster says:

    Seems a long time since any posts on this blog, however, still have the need to return to multiple locations from 1 page.

    I have an application whereas we have multiple queues, these are Interactive reports with various limiters, each of which has a SCRIPT_ID link into the same updateable FORM page.
    So, multiple entry points to 1 update needing to return to multiple entry points.
    Building on the principle described by Sara, we need the previous page to be identified to tell the branch where to go.
    1. Create a table called PREVIOUS_PAGE…Columns are PAGE_NUMBER & APP_USER.

    2. For all 3 entry point pages (Queues), create 2 processes
    a. 1 Before header & 1 After header (not sure it matters…These 2 just need to run each time the pages load via the TABs – In sequence)
    b. Processes SQL
    DELETE PREVIOUS:

    DELETE FROM PREVIOUS_PAGE
    WHERE APP_USER = :APP_USER;

    PREVIOUS PAGE:

    INSERT INTO PREVIOUS_PAGE (PAGE_NUMBER, APP_USER)
    VALUES (:APP_PAGE_ID, :APP_USER);

    So, essentially what you’re doing is clearing the entry & inserting the page number before you link-Branch to the update point. You should never have more than 1 entry “per user” at a time

    3. Create an item (Text) on the Edit page called *P22_RETURN_PAGE (*your page #, this item is populated via a SQL Query:
    (After you check it out, make this HIDDEN)

    select
    PAGE_NUMBER
    from
    PREVIOUS_PAGE
    where APP_USER = :APP_USER

    4. Do what Sara said, create the return button to submit & the Branch to redirect to the &P22_RETURN_PAGE.

    Works great!

Comments can no longer be submitted.