Insert values into database and return them into interactive grid (APEX 5.1)

3k views Asked by At

I have a Form with Select list item P2_PERSON (it's type is Shared component and it shows names of people that are in the PERSON table in database), two Date pickers P2_DATEFROM and P2_DATETO and one hot button labelled GO. Below, on the same page (see picture 1) is Interactive Grid (a new region in apex 5.1, looks like a fresh and powerful feature). What I need to do, and can't find the answer anywhere is: after the person is selected in Select list labeled Osoba, what can be seen in the first picture, and two dates are chosen from two Date pickers, clicking the GO button 5 rows are inserted in table CONTROL_TT and presented on Interactive grid on the page. Difference between dates must not be larger than seven days to avoid too many inserts in the table.

Each day in the range of dates entered represents one new inserted row in CONTROL_TT table and that date is stored in date column of every row.

Also, person_id collected (or passed) from P2_PERSON Select list Item is stored in person_id column of CONTROL_TT table. Columns of CONTROL_TT table are

(control_id, person_id, date, time_from, time_to, hours_total, project_id, status, desc, person_id_accept_req)

Id column is populated trough sequence seq_evidencija

time_from, time_to, hours_total and desc are inserted/tiped (inputed) manually by the user when the interactive Grid is populated with data. project_id will be Select list (from table Project in db) on Interactive grid and status is the same as project_id using Status table as reference for data. Tnx


Web page in browser look

Look from apex

1

There are 1 answers

1
Cristian_I On BEST ANSWER
  1. Your GO button must have Action: Submit Page.
  2. Create validation Type: PL/SQL Expression having this code:

    to_date(:P2_DATETO, 'dd-mon-yyyy')-to_date(:P2_DATEFROM, 'dd-mon-yyyy') <=7

(note, please modify the date format if needed) with condition When Button Press: GO and some message that you want to display. 3. Create a process that runs on condition When Button Press: GO with this PL/SQL Code:

BEGIN 
    FOR i IN 1..(To_date(:P2_DATETO, 'dd-mon-yyyy')-To_date(:P2_DATEFROM, 'dd-mon-yyyy')) 
    LOOP 
        INSERT INTO control_tt (person_id, DATE) 
        VALUES (:P2_PERSON, To_date(:P2_DATETO, 'dd-mon-yyyy') + i - 1); 
    END LOOP; 
END;