Wednesday, February 18, 2009

Finding Parent Page in APEX

While working with Oracle Application Express, Sometimes we may need to find parent page or previously visited page. We may have some processing on a page which depends on previously visited page. We will see how to find previously visited page in APEX.

Finding Previously visited page in APEX

Oracle Application Express is packaged with Oracle Database. It runs under database environment. In APEX, It is possible to find out previously visited page. APEX stores data related to application in tables. This is known as metadata. i.e. Data about data. APEX metadata consist of several tables. There are several views created on these tables. These views can be accessed by application developer (Note that this views can be accessed in readonly mode. But this is good enough for us). apex_workspace_activity_log is one of such view.

Have a look at this SQL Query. It can be executed in your apex page.

select page_id
from (select page_id
from apex_workspace_activity_log
where application_id = :app_id and apex_user = :app_user and apex_session_id = :app_session and page_id <> :app_page_id order by seconds_ago)
where rownum = 1

This query gives you last visited page. You need to use "page_id <> :app_page", otherwise it will give you the most recently used page. And most recently page would be the page where you are executing your query.

Generally you will be expecting previously visited main page. sometimes, there may be popup pages available on parent page. If user visits popup page, you would not get expacted result. In such circumstances, you can use this clause

where page_id not in (list of popup pages).

If you can find out most possible parent page then you can use this clause.

where page_id in (list most possible parent page).

This clause will be most appropriate if you know possible parent pages.

1 comment:

Anonymous said...

Excellent stuff! Just what I was looking for in Apex.

Regards,

Fredrik