Developing Dynamic Tabular Forms – Updated

Several years ago I posted a series about using collections and manual tabular forms to create a highly configurable questionnaire that allowed for using a different type of control (and different LOVs) for each row within the same tabular form column. This functionality is still in use in the original application I developed it for, although a few adjustments had to be made as we updated APEX versions and moved away from using legacy javascript. Recently I had new use cases for the same approach and expanded on it further.

I’ve updated the original posts for use in APEX 24.2 and 26.2 along with including the expanded functionality and have created an updated demo application here (Guest/Pl@net_APEX1):
Dynamic Tabular Forms

The original posts can be found here:
Collections and Manual Tabular Forms – A powerful combination
Developing Dynamic Tabular Forms Part 1 – Questionnaire Setup Page
Developing Dynamic Tabular Forms Part 2 – Building the dynamic SQL statement
Developing Dynamic Tabular Forms Part 3 – Creating the tabular form
Developing Dynamic Tabular Forms Part 4 – Saving the data in the tabular form
Developing Dynamic Tabular Forms Part 5 – Performing calculations

An Interactive Report with Dynamic Column Headings

Originally posted December 12, 2016; updated for APEX 24.2/26.2.

I recently developed a tool that would allow users to select a data view and use the built in tools of an Interactive Report to sort, filter, and download the data.  The different views available to the users have a different number of columns and different column headings, so the display of the report had to be dynamic.

In comes collections again.  To accomplish this takes a little bit of time but it is actually quite simple and once it’s set up you can view any data view in the report as long as it contains 50 columns  or less.

First you’ll need a select list to display the list of data views and an interactive report.  Set the Page Action on Selection for the select list to Submit Page and create a page process to create your collection:

DECLARE
 v_sql VARCHAR2(2000);
BEGIN
 IF :P1_VIEW_NAME IS NOT NULL THEN
   v_sql := 'select * from ' || :P1_VIEW_NAME;
   IF apex_collection.collection_exists 
    (p_collection_name => 'EXTRACTION_VIEW') THEN
     apex_collection.delete_collection (p_collection_name => 'EXTRACTION_VIEW');
   END IF;

   IF NOT APEX_COLLECTION.COLLECTION_EXISTS 
    (p_collection_name => 'EXTRACTION_VIEW') THEN
     APEX_COLLECTION.CREATE_COLLECTION_FROM_QUERY(
     p_collection_name => 'EXTRACTION_VIEW',
     p_query => v_sql);
   END IF;
 END IF;
END;

Set your source for the interactive report:

select *
from apex_collections
Where collection_name = 'EXTRACTION_VIEW';

Here’s the tedious part.  You’ll need to create a page item for each of the 50 column headings.  I named mine PX_C0XX_HEADING.  Then in your interactive report you’ll need to do two things:

  1. Set the Column Heading for each column to the corresponding page item (for example &P1_C001_HEADING.)
  2. In the Conditional Display for each column, set the condition type to Exists (SQL query returns at least one row) and enter the following, substituting the appropriate column name:
select 1
from apex_collections
where c0XX is not null
and collection_name = 'EXTRACTION_VIEW';

The final piece is to populate the column heading page items.  I created a database function to determine the column name:

CREATE OR REPLACE FUNCTION get_extraction_column_heading (p_view_name IN VARCHAR2
 , p_data_type IN VARCHAR2, p_column_id IN NUMBER) RETURN VARCHAR2 IS
  CURSOR get_column_heading_c IS
  SELECT column_name
  FROM all_tab_columns
  WHERE table_name = p_view_name
  AND column_id = p_column_id;

  v_column_name all_tab_columns.column_name%TYPE;
BEGIN
  OPEN get_column_heading_c;
  FETCH get_column_heading_c INTO v_column_name;
  CLOSE get_column_heading_c;

  RETURN v_column_name;
END;

Then create an After Header computation for each column heading page item to call the function:

get_extraction_column_heading(:P1_VIEW_NAME, 'VARCHAR2', 1);

The number for the last parameter (P_COLUMN_ID) will correspond to the number of the column heading.

Note:  You may want to consider putting the same condition that you put on your columns on the computations for the column headings as well to eliminate unnecessary database calls.  I did not have any issues with this on my production application, but when creating the demo app I recieved numerous I/O errors which resolved after putting the condition on the computations.

You can access the demo application here (credentials are guest/demo): Interactive Report with Dynamic Column Headings

Generating a Crystal Report from APEX

Originally posted December 12, 2016; updated for APEX 24.2/26.2.

All of the reports in the application I support are written in Crystal Reports 16.  When we migrated the application from Oracle Forms to APEX several years ago, we did not want to have to re-write all of the reports as there are quite a few.  Although I could not find a way to implement a Crystal Report viewer in APEX, I was able to develop a method to generate a .pdf from Crystal and display the report on the screen in .pdf format.  This functionality is still working well 10 years later.

First I developed some setup pages and a reporting tool application that allows users to select a report and enter the parameters.  I used the same methodology as I did in my blog series “Developing Dynamic Tabular Forms” only this time instead of a questionnaire being captured, report parameter selections are being captured.  It’s important to note that as a part of your report parameter setup, you will need to include a sequence column on the report parameters to ensure that the parameters are displayed on the screen in the same order as they appear within your Crystal report.  I also created a “print queue” table and page to allow users to view their print jobs.  Your print queue table needs to include the following:

  • name of the report to be generated
  • parameter string
  • output file name
  • status – I used ‘S’ for Submit, ‘P’ for Processing, ‘C’ for ‘Complete’ and ‘E’ for ‘Error’
  • the url of the folder where the report output will be generated to

Whenever a report request is submitted, a page process first updates the collection with the values entered in the tabular form and then a second page process cycles through the collection, concatenates the parameters entered together with double pipes, and then inserts a record into the print queue via a database procedure.  I chose double pipes because I needed a delimiter that would not appear within one of the report parameters and I would also be passing the string to a database procedure to insert the print queue record so commas could not be used.

The print queue page that allows users to monitor their print jobs also contains a link column that users can click on to open the .pdf in a separate browser window when it has finished generating.  I put the page on a refresh timer and provided a manual refresh button as well.

Our Crystal reports reside on a Tomcat server.  Using Java, I wrote code that queries the print queue table for records that are in ‘S’ status, cycles through them, makes the required Crystal Java SDK calls to generate the report(s) as a .pdf, and sets the status of the print queue records to ‘C’ when complete (or ‘E’ if an error occurred). An automated background process runs this multiple times per day.

It’s been a minute

It’s hard to believe it’s been almost 8 years since my last post! A lot has changed and I have learned a lot since then. I am still an APEX developer and now manage a team of developers. I’m looking forward to sharing new techniques, discoveries, and solutions as I continue exploring Oracle APEX.

Displaying text with carriage returns

To display text that contains carriage returns and white space with the formatting in tact in display only columns in Interactive Reports, Tabular Forms, and Interactive Grids, enter the following in the Column Formatting – HTML Expression for the column:

<span style="white-space:pre-wrap; font-family:Segoe UI; font-size:12px;
 display:block;">#COLUMN_NAME#</span>

Note: for Interactive Grids, use &COLUMN_NAME. instead of #COLUMN_NAME#.  You will also need to set the column type to “HTML Expression”.

For IR and Tabular Forms, under Security, set Escape special characters to Yes.

APEX 5.1 Interactive Grid challenges

I love Interactive Grids, I hate Interactive Grids.  I love the enhanced functionality they bring to users by combing the things we love about the Interactive Reports with the editing capability of a tabular form as well as being able to have multiple IG’s on a single page.  Now that I have used them with regularity I am discovering some challenges with their use which is where the hate part comes in.  Please note, I am using version 5.1.4 of APEX.

Multiple Interactive Grids on a page

  • Performance – if you have multiple IG’s on a single page, be prepared for some performance issues when loading your page.  Changing the timing of when your data loads to be on demand will not likely help this either unless you have tuning issues with your queries. The issue stems from the initialization of the grid which is very JavaScript intensive, so each grid you add to your page will add to the issue. Slow performance appears to occur most noticeably using Microsoft browsers such as IE and even Edge and is least noticeable when using Chrome.  There was a bugfix released in 5.1.3 that brought some improvement but the issue still persists.  I have a page that has several IG’s on it and in Edge it takes 26 seconds to load whereas in Chrome it’s 11 seconds.  This issue has been raised many times and the APEX team is aware so hopefully in a future release we will see improvement here.  In the meantime I am instructing my users to use Chrome for the best experience.
  • Scroll Pagination – with multiple IG’s on a page, if you set the Pagination to “Scroll” only 40 records will display in the grid.  The record count displayed will be correct and there will be a large white space where the rest of the records should display.  You also cannot set the number of rows displayed in the Actions menu.  This issue occurs when using an IG on a modal page as well.

Read Only Interactive Grids

When conditionally setting an Interactive Grid to read only, the Primary Key (or ROWID) column which is normally hidden displays in the grid.  Fortunately there is a workaround to this issue, and I had a good chuckle when this solution was suggested to me.  Setting the Server-side Condition “Page/Region is NOT Read Only” on the APEX$ROW_ACTION column in the grid resolved this issue for me.

Wrapping of text/auto row height

One of the nice features of the Interactive Report is that large columns will automatically wrap and row heights will auto adjust to accommodate the wrapping text.  This functionality is not currently present in the Interactive Grid.  I have learned that the row selection and row action columns are actually in a separate grid than the data columns when the IG is rendered on the page which explains the absence of this functionality as it would require coordinating two separate grids.  Depending on your needs there are some workarounds to this issue, though none are perfect and I hope in a future release this can be addressed.

If you can live without the APEX$ROW_SELECTOR and APEX$ROW_ACTION columns, you can exclude them from your grid and add the following to your Inline CSS for the page:

#static_id .a-GV-table td, #static_id .a-GV-table th {
  overflow: visible;
  overflow-wrap: break-word;
  text-overflow: ellipsis;
  white-space: normal;
}

If you must keep your select and row actions columns, you can try the following.  The code to wrap the text must be entered for each column where needed and you must set the row height to a fixed value via css.  The downsides to this solution are all rows will be the same height even if the columns in that row do now wrap and if you do not make the row height tall enough to accommodate the maximum amount of wrapping possible you still won’t be able to see all the data in the column.  This is less of an issue for editable columns as you can view the full text placing the column into edit mode but for display only columns this is a problem.

In your Inline CSS for the page (adjust the number of pixels to meet your needs):

#static_id .a-GV-cell {
  height: 80px;
}

.wrap-cell {
  max-height: 64px;
  white-space: pre-line;
  overflow: hidden;
}

For each column in your IG that needs to wrap, enter the following under Advanced – JavaScript Code (replace &DESCRIPTION. with your column name):

function_config

I appreciate the efforts the developers at Oracle have done to bring us this great functionality despite the issues I have run into.  With any new technology, it is expected there will be a few hiccups when it is first launched and I look forward to future improvements being made to the Interactive Grid control.

 

 

 

Font Awesome icons in select lists

I needed to be able to display an icon along with text in a select list.  Fortunately the icons I needed were available in the Font Awesome library that comes with APEX and after much trial and error and research I was able to come up with a solution.

The key to this solution is locating the unicode for the icon you want to use and adding an escape function to your select list sql.  Below is my list of values query:

fa_select_list_query

A cheatsheet for the Font Awesome can be found here https://fontawesome.com/cheatsheet.  I found when playing around not all icons will work with this method so YMMV.

In addition you will need to set some Custom Attributes under the Advanced properties for your select list column:

icon_select_list_custom

I implemented this solution in version 5.1.4.  When I tried to create a demo app in 18.2 it unfortunately did not work.

 

Upgrading from 5.0 to 5.1: Lessons Learned Part I

I am in the process of upgrading a set of applications currently in APEX 5.0 to APEX 5.1.  Some of these applications were initially created in version 4.2 and have been through one upgrade already, while others were initially created in version 5.0.  The main goal of the initial pass was to get the applications working as is in the new version without making major changes to functionality or taking advantage of the newer features.

The upgrade from 5.0 to 5.1 was easier than than upgrade from 4.2 to 5.0 and required only minor adjustments.  The biggest issue was that a couple of applications initially developed in 4.2 used the CSS Bar Chart Plug-in which survived the 5.0 upgrade but is no longer usable in 5.2  These charts were easily re-written using the HTML 5 Bar Chart Plug-in.  Other issues encountered:

  • In order for the help text to display for a page item, the Label attribute must be entered for the page item.  Most text items had this attribute entered already, but was missing from most of the radio buttons in my applications.  To easily find any page items that had help text but were missing labels, I queried the APEX_050100.APEX_APPLICATION_PAGES_ITEMS view in the database.

 

  • Modal pages that used the Skillbuilders SaveBeforeExit Plug-in to detect changes had to be altered to prevent the change detected warning from appearing a second time after the modal is closed.  In my modal pages in 5.0, the plug-in did not actually prompt the users – I used it only to detect a change and wrote a dynamic action to prompt users if a change was detected when the modal page was closed.   In the dynamic action that closes the modal I had to add an additional javascript action after the user was prompted to disable the warning :
$(document).apex_save_before_exit('disableWarning');

 

  • Custom link columns referencing a URL in tabular forms had to be modified.  Previously to reference a value in the row it would be referenced using #ITEM_NAME# but after the conversion I had to change the reference to &ITEM_NAME. in order for the link to work.

 

In a future pass I will address converting the tabular forms, where appropriate, to the new interactive grid.  I did a test conversion and found that too many adjustments would need to be made with how my applications are written to be able to tackle it in the time frame I had.  My initial impression of the new interactive grid is good though, and I look forward to playing with it.  I will detail this conversion in a future blog post.

 

Displaying a modal dialog for page item help

I wanted to be able to display a modal dialog containing a small report as help for an item.  This is easy to implement and can really customize and enhance the help displayed for an item.

First create your modal dialog page you want to display as help.  Make sure if this modal will be called from another modal that you set Chained Dialog to No for the modal help page.

On the page you want to call the modal help from, create a hidden page item to store the url.  Set the Source Type to PL/SQL Expression and in the Source value or expression enter the following code, replacing ’38’ with the page number of your modal help page:

apex_util.prepare_url('f?p=&APP_ID.:38:&SESSION.::NO:38:', p_triggering_element => '$(''body'')')

 

Add the following code to the Function and Global Variable Declaration of the page you will be call the help from:

function showHelp() {
 eval($("#PX_YOUR_PAGE_ITEM").val());
}

 

Last, for the page item you want to display help for, add the following code in the Post Element Text.  This will display the help button icon that you normally see when help is entered for a page item and sets the onClick for the button to the showHelp function:

<button class="t-Button t-Button--noUI t-Button--helpButton js-itemHelp" title="Help" aria-label="Help" tabindex="-1" type="button" onclick="showHelp()"><span class="a-Icon icon-help" aria-hidden="true"></span></button>

You can access the demo application here (credentials guest/demo): Modal Dialog Help Demo.

 

Skillbuilders Super LOV disappearing on APEX 5 modal page

I use the Skillbuilders Super LOV liberally throughout my APEX applications.  I had one instance where the LOV exhibited strange behavior when on a modal page.

When entering a search string in the LOV and either pressing the search icon or pressing TAB, the LOV behaved as expected.  If I pressed ENTER instead, the LOV modal page appeared for a split second and then disappeared and the page would submit.  I could not tell if you the fact that it was on a modal page made a difference or not, although I have used the control on a modal page before.

My researched showed that several others had experienced this same issue but not a lot of solutions were found.  The only solution I did find pertained to having a hidden column as a map to item in the LOV, which was not the case for me.  You can view the discussion for this solution here:  https://community.oracle.com/thread/3785062

I tried deleting and rebuilding the LOV and placing it in a different position on the page with no luck.  The workaround I finally came up with was to code the ENTER key to perform as the TAB key on my modal page.  To do this, add the following code to your page:

keydown