May 18

I had a requirement today to pass through the REGION_ID value for every row in an APEX report to perform a row action using javascript, i.e. delete comments. In this case I was deleting a comment via AJAX and reloading the APEX report using $a_report, which requires the REGION_ID parameter to be passed in. Hence the topic of this post….

Unfortunately the #REGION_ID# substitution string is not replaced within the query source before/after the query is executed by the APEX engine (it would be nice if this was supported including the #REGION_STATIC_ID#) so what we get in our HTML report output is the raw substitution string #REGION_ID#. Now there were a couple of ways to workaround this problem but the simplest one I found was to do a join against “APEX_APPLICATION_PAGE_REGIONS” within the region query itself. e.g.

SELECT '<table><tr><td><strong>Comment By:</strong> '||portal_security.get_user_full_name(:APP_USER)||', '||to_char(updated_on, :APP_DATE_TIME_FORMAT)||'</td></tr><tr><td>'||comments||'</td></tr><tr><td><div><a href="#" onclick="Ext.app.deleteComment('''||r.region_id||''','''||comment_id||''','''||wwv_flow_item.md5(comment_id,comments)||''');">Delete</a></div></td></tr></table>' tech_comment
FROM   cmgmt_comments_vw
,      apex_application_page_regions r
WHERE  cust_id          = : P13_CUST_ID
AND    r.region_name    = 'Recent Sales Comments'
AND    r.application_id = :APP_ID
AND    r.page_id        = :APP_PAGE_ID
ORDER BY created_on desc

The only issue in the above query is that we do a filter on the region name, which if changed will break the query. So it’s important for us to document this so it’s not overlooked when changes occur to the region title. It also requires that we have a unique region title as well which may not always be the case, so a secondary filter would be added to the query to ensure we only ever return the one row/region we are interested in as we use a cartesion join (maybe display sequence etc.). Not exactly elegant but it’s the solution/workaround for now :) Here’s an example screenshot of the report:

Leave a Reply

preload preload preload