Friday, 5 June 2015

Page processing after wpg_docload download_file call

Problems with page refresh when using wpg_docload download_file function

APEX 4.2.6 workaround with APEX_UTIL.SET_PREFERENCE

Situation a standard form with report parameters

where user have an ability once reports are run result is either saved on shared Network Drive or it is saved temporarily in the custom file table and presented to them on the screen for individual download in a separate page region. See image below.

Idea was to be able to run report for an account manager that can have multiple Clients and for each of these clients man can have multiple contracts. Sort of Select All Clients and All Contracts for an account manager version of report with download option.

With only one exception that if you select only one client and only one specific contract users would get document downloaded in a browser in a window familiar to all of us.

All good so basic idea is there and all was working fine except for this one case when individual contract is selected. Let me try to explain why.

When a Run button (that submits the page) would be processed above region would be normally refreshed and users would get the latest report results. But problem with download function for individual contract was in this code:

where apex_application.g_unrecoverable_error would prevent APEX to refresh the page as it is basically stopping APEX engine and users would be left with older version of report in their download region while they would still get to download the latest results.

To avoid this problem I decided not to use g_unrecoverable_error and to use APEX SET_PREFERENCE with JQuery. More about USER PREFERENCE functionality you can find in any APEX guide and I will not go into details of it. Basically it can be used for temporarily setting values for current user session and is ideal as a global variable for all non standard values within your applications.