2 Replies Latest reply: Apr 28, 2014 3:19 PM by C Patel RSS

    Dynamic action to truncate collection

    C Patel

      Hi,

       

      I have a form with a radio button (P3_IMPORT_FROM) which allows the user to choose whether they would like to copy/paste data into a text area or upload a csv file of records.  Once the user clicks on a "Load" button, a PL/SQL page process executes to parse the records and populate an apex_collection named MASS_UPLOAD.  As a result, the value of a display-only page item (P3_RECORDS_UPLOADED) also changes as it is based on PL/SQL Expression of APEX_COLLECTION.COLLECTION_MEMBER_COUNT('MASS_UPLOAD').

       

      Any time the user changes P3_IMPORT_FROM, it should truncate the APEX_COLLECTION in case they are switching back and forth between modes.  I have a dynamic action (as below) which executes when the radio button changes.   The collection is truncating, but why isn't P3_RECORDS_UPLOADED resetting to 0?  It still displays the total from a past load.  I have tried adding an a refresh action to this dynamic action to refresh P3_RECORDS_UPLOADED but nothing happens.  Any suggestions?

       

      Dynamic Action

      Event: Change

      Selection Type:  Item(s)

      Item(s): P3_IMPORT_FROM

      Condition:  No Condition

      True Actions:  Execute PL/SQL Code

       

      DECLARE
        v_count PLS_INTEGER := 0;
      BEGIN
      if apex_collection.collection_exists(p_collection_name=>'MASS_UPLOAD') then
         apex_collection.TRUNCATE_COLLECTION(p_collection_name=>'MASS_UPLOAD');
         v_count := APEX_COLLECTION.COLLECTION_MEMBER_COUNT(MASS_UPLOAD');
         APEX_UTIL.SET_SESSION_STATE('P3_RECORDS_UPLOADED',v_count);
      
      end if;
      END;
      
      

      Event Scope:  Static

       

       

      APEX 4.2.4

        • 1. Re: Dynamic action to truncate collection
          fac586

          C Patel wrote:

           

          The collection is truncating, but why isn't P3_RECORDS_UPDATED resetting to 0?  It still displays the total from a past load.  I have tried adding an a refresh action to this dynamic action to refresh P3_RECORDS_UPLOADED but nothing happens.  Any suggestions?

          Firstly, decide what the item is called: is it P3_RECORDS_UPDATED or P3_RECORDS_UPLOADED? When that's clear, ensure that's the name used in the PL/SQL block to reset the item session state, and include it in the Page Items to Return dynamic action property to update the value in the browser.

          • 2. Re: Dynamic action to truncate collection
            C Patel

            My fault, I updated the original post to indicate P3_RECORDS_UPLOADED.   I've verified that my code referenced this name as well.  As you suggested, I've added it to Page Items to Return and it works!  Thank you!