oracle-apex

Populating Form Items with Values from an Uploaded CSV File in Oracle APEX


I have a form on a page where I want to populate item values by uploading a CSV file containing item names and their corresponding values. I am creating a collection based on the CSV content. How can I set the form item names with the corresponding values from the Collection?

I am trying to call the process on pre rendering after header.

    DECLARE
    l_field_name  VARCHAR2(32767);
    l_field_value VARCHAR2(32767);
BEGIN
    FOR rec IN (SELECT * FROM APEX_COLLECTIONS WHERE collection_name = 'POPULATE') LOOP
        l_field_name := rec.c001;  
        l_field_value := rec.c002; 
        EXECUTE IMMEDIATE 'BEGIN :1 := :2; END;'
        USING OUT l_field_name, l_field_value;
    END LOOP;
END;

but there value is not updating.


Solution

  • Page items are available as pl/sql variables in the apex context. You can reference them using bind variable syntax and assign a value using the assignment operator :=

    :P1_MYPAGEITEM := 'Foobar';
    

    Alternatively, use APEX_UTIL.SET_SESSION_STATE.

    For your case, it sounds like you need the 2nd option:

    DECLARE
        l_field_name  VARCHAR2(32767);
        l_field_value VARCHAR2(32767);
    BEGIN
        FOR rec IN (SELECT * FROM APEX_COLLECTIONS WHERE collection_name = 'POPULATE') LOOP
            l_field_name := rec.c001;  
            l_field_value := rec.c002; 
            APEX_UTIL.SET_SESSION_STATE(p_name => l_field_name,p_value => l_field_value);
        END LOOP;
    END;