Skip to main content

Dynamic 'My Favorites' Links in your APEX Application

For a (even more) Web 2.0 like look-and-feel in your APEX application you can define a dynamic region 'My Favorite Tasks', that shows links to the pages you visit most frequently.
For these favorites we can query the APEX repository. Follow these steps to get this thing working:

  1. Enable logging on Application Level. Enabling the logging will result in records in the view apex_workspace_activity_log.
  2. Create a Report Page with a region based on a SQL Query.
  3. Enter the query to show the links for the three most visited pages:
select htf.anchor( 'f?p='||:APP_ID||':'||page_id||':'||:APP_SESSION
, page_name ) Task
from

(
select page_name
, page_id
, count(*)
from apex_workspace_activity_log
where application_id = :APP_ID
and apex_user = :APP_USER
and page_id <> :APP_PAGE_ID
group by page_name, page_id
order by 3 desc
)
where rownum <= 3
In a next post I will show how you can embed this report page in any other page in your application.

Comments

Anonymous said…
Nice Post Roel,

This can also be done using apex view apex_activity_log instead of wwv_flow_activity_log. Using apex_activity_log you would not need steps 1 and 2.

Thanks,
Todd
Stew said…
For those who were initially as clueless as me when they read "Enable logging on Application Level", that means to navigate to Shared Components -> Application Definition and set Logging := Yes in the Name section.

Stew
Stew said…
Roel,

It looks like the better bet would be to use the apex_workspace_activity_log table, since it's already granted to the workspace.

I'd use an inner query like:

SELECT *
FROM (SELECT page_id, page_name, MIN(seconds_ago) last_ones
FROM apex_workspace_activity_log
WHERE application_id = :APP_ID
AND page_id <> 101 -- Login page
AND userid = :APP_USER
GROUP BY page_id, page_name)
WHERE rownum <= 3
ORDER BY 3;

Or maybe I'm missing something?
Roel said…
Todd & Stew,

A combination of both suggestions seems to result in the best query:
- use apex_workspace_activity_log instead of the wwv_flow_activity_log (although the apex_.. view only contains data of the last 14 days).
- I think I don't have to exclude the login page, as there is no known user at the time that page pops up.
- the ORDER_BY should be inside the inline view, otherwise you don't get the Top-3.
- use APEX_USER instead of USERID
- exclude the current page from the query by filtering on :APP_PAGE_ID

I updated my post with your suggestions!

Thanks,
Roel
Anonymous said…
Excellent Roel.

I really like this.

One thing I found though was that my development team and I use some quite obscure 'Developer' coded page titles (e.g. Developer initials, module reference etc) and the Page Names are set to something more user friendly, after all, the Page Name is what the user sees at the top of their web browser.

A join in the query, as shown below, gave us a more user friendly result. Of course, if your page names and titles are the same then you needn't bother.

Just my thoughts.

As I said, nice post.

select htf.anchor( 'f?p='||:APP_ID||':'||page_id||':'||:APP_SESSION
, page_title ) "Favourite Pages"
from
(
select aap.page_title
, awal.page_id
, count(awal.page_id)
from apex_workspace_activity_log awal
join APEX_APPLICATION_PAGES aap on aap.application_id = awal.application_id and aap.page_id = awal.page_id
where awal.application_id = :APP_ID
and awal.apex_user = :APP_USER
and awal.page_id <> :APP_PAGE_ID
group by aap.page_title, awal.page_id
order by 3 desc
)
where rownum <= 3
Stew said…
Nice collaboration guys! :-)
Anonymous said…
Hi this adaptation will only show pages that are linked to from tabs:

select htf.anchor( 'f?p='||:APP_ID||':'||page_id||':'||:APP_SESSION, page_name ) Task
from (select act.page_name
, act.page_id
, count(*) "load_count"
from APEX_APPLICATION_TABS tab
join APEX_WORKSPACE_ACTIVITY_LOG act on tab.tab_page = act.page_id
where act.application_id = :APP_ID
and act.apex_user = :APP_USER
and act.page_id <> :APP_PAGE_ID
group by act.page_name, act.page_id
order by 3 desc)
where rownum <= 10;

Greets,
Maurice Kremer

Popular posts from this blog

Filtering in the APEX Interactive Grid

Remember Oracle Forms? One of the nice features of Forms was the use of GLOBAL items. More or less comparable to Application Items in APEX. These GLOBALS where often used to pre-query data. For example you queried Employee 200 in Form A, then opened Form B and on opening that Form the Employee field is filled with that (GLOBAL) value of 200 and the query was executed. So without additional keys strokes or entering data, when switching to another Form a user would immediately see the data in the same context. And they loved that. In APEX you can create a similar experience using Application Items (or an Item on the Global Page) for Classic Reports (by setting a Default Value to a Search Item) and Interactive Reports (using the  APEX_IR.ADD_FILTER  procedure). But what about the Interactive Grid? There is no APEX_IG package ... so the first thing we have to figure out is how can we set a filter programmatically? Start with creating an Interactive Grid based upon the good old Employ

apex_application.g_f0x array processing in Oracle 12

If you created your own "updatable reports" or your custom version of tabular forms in Oracle Application Express, you'll end up with a query that looks similar to this one: then you disable the " Escape special characters " property and the result is an updatable multirecord form. That was easy, right? But now we need to process the changes in the Ename column when the form is submitted, but only if the checkbox is checked. All the columns are submitted as separated arrays, named apex_application.g_f0x - where the "x" is the value of the "p_idx" parameter you specified in the apex_item calls. So we have apex_application.g_f01, g_f02 and g_f03. But then you discover APEX has the oddity that the "checkbox" array only contains values for the checked rows. Thus if you just check "Jones", the length of g_f02 is 1 and it contains only the empno of Jones - while the other two arrays will contain all (14) rows. So for

Stop using validations for checking constraints !

 If you run your APEX application - like a Form based on the EMP table - and test if you can change the value of Department to something else then the standard values of 10, 20, 30 or 40, you'll get a nice error message like this: But it isn't really nice, is it? So what do a lot of developers do? They create a validation (just) in order to show a nicer, better worded, error message like "This is not a valid department".  And what you then just did is writing code twice : Once in the database as a (foreign key) check constraint and once as a sql statement in your validation. And we all know : writing code twice is usually not a good idea - and executing the same query twice is not enhancing your performance! So how can we transform that ugly error message into something nice? By combining two APEX features: the Error Handling Function and the Text Messages! Start with copying the example of an Error Handling Function from the APEX documentation. Create this function