Forum Stats

  • 3,782,429 Users
  • 2,254,644 Discussions
  • 7,880,078 Comments

Discussions

Checkboxes in oracle apex

Manu1
Manu1 Member Posts: 15 Red Ribbon
edited Jul 12, 2017 12:09PM in APEX Discussions

I am a newbie in Oracle Apex so please excuse me for very naive questions. I was trying to use simple checkbox using LOV to create insert statement in the database table.

Apex version: 5.1

DB version : 12.1

Steps I followed

1. Created checkbox item based on LOV ( dynamic from a table )

2. On submit button, created a dynamic action which when true, executes a pl/sql block that inserts value in a table

Problem is that I am not getting selected checkbox values in APEX_APPLICATION.G_F01 as I thought it was supposed to ( my understanding based on google examples )

Can anyone point me a right direction ?

Debug log says

0.032540.00424..Session ID 33840784999852 can be used
4

8%

0.036780.00009
...Setting session time_zone to -04:00
4

0%

0.036870.00095
...Check for session expiration:
4

2%

0.037820.00066
......Validate item page affinity
4

1%

0.038470.00039
......Read Page Item values and validate protected items
4

1%

0.038860.00005
.........Name=SELECT_DATABASES (id=18221404794302706), value=JS01PM:CREP01PB:CREP02PB, checksum=
4

0%

0.038910.00010
Session State: Save "Items to Submit"
4

0%

0.039000.00078
Session State: SELECT_DATABASES=>JS01PM:CREP01PB:CREP02PB       <==== This is the value I am getting from checkbox which is correct
4

1%

0.039780.00010
... do not save: same value / password / no session
4

0%

0.039880.00174
Run NATIVE/PLUGIN= request
4

3%

0.041620.00601
...Execute Statement: begin apex_debug.message('Value of array f01 at position'||APEX_APPLICATION.G_F01.count ); FOR i in 1 .. APEX_APPLICATION.G_F01.count LOOP INSERT INTO DR_DRILL_ACTIONS SELECT SYSDATE, APEX_APPLICATION.G_F01(i), 'PRECHECKS', 'STARTED', NULL FROM DUAL; commit ; END LOOP; end;
4

12%

0.047630.00381
Value of array f01 at position 0        <== This is output of APEX_APPLICATION.G_F01.count which is 0. 

I think I am missing some very simple thing and there's surely a gap in my understanding. Can anyone point that to me ?

Thanks in advance.

Tagged:
Manu1Shilpi Pauranik-Oracle

Best Answer

  • Pavel_p
    Pavel_p Member Posts: 2,312 Gold Trophy
    edited Jul 12, 2017 5:13AM Accepted Answer

    Hi,

    you mixed together few things. You created a page item PX_CHECKBOX and trying to reference APEX_APPLICATION.G_Fxx arrays (you chose g_f01 but there are 50 of them at your disposal). There is absolutely no relation between your PX_CHECKBOX page item and APEX_APPLICATION.G_Fxx thus there is no reason why APEX_APPLICATION.G_F01.count should return anything else than 0. Please, read the documentation to APEX_ITEM CHECKBOX2 Function .

    Let's have a following example:

    Create a Classic/Interactive report based on the select in documentation (do not forget to set the Escape Special Characters attribute of your Select column to No)

    SELECT APEX_ITEM.CHECKBOX2(1,empno,'CHECKED') "Select",--p_idx parameter here is 1  ename, jobFROM emp

    and add a Submit button. In this case is the p_idx (Number that determines which APEX_APPLICATION global variable is used. Valid range of values is 1 to 50. For example 1 creates F01 and 2 creates F0)  parameter = 1, so ONLY CHECKED values will be stored in G_F01 array after page submission (if do not select any of them, g_f01 count will be still 0).

    If you used APEX_ITEM.CHECKBOX2(2,empno,'CHECKED') "Select" in your select statement, checked values would be stored in G_F02 array etc.

    Hopefully now it's clear why your g_f01 contains 0 elements.

    Regards,

    Pavel

Answers

  • Sadath.Saad
    Sadath.Saad Member Posts: 152
    edited Jul 11, 2017 7:31AM
    Problem is that I am not getting selected checkbox values in APEX_APPLICATION.G_F01 as I thought it was supposed to ( my understanding based on google examples )

    Hi,

    May i know how you inserting into table, Is there any condition..

    If you using plsql and check box in the form of item..

    then use directly that item itself in the plsql like ":P5_CHECKBOX" instead of APEX_APPLICATION.G_F01

  • Manu1
    Manu1 Member Posts: 15 Red Ribbon
    edited Jul 11, 2017 11:01AM

    Please correct me where ever i am wrong

    As per my understanding, when we submit LOV as item with a simple checkbox, shouldn't return value get mapped to apex_application.g_f01 variables ?

    am i missing something ? I am trying to insert data based on this assumption only.

  • fac586
    fac586 Senior Technical Architect Member Posts: 20,345 Red Diamond
    edited Jul 11, 2017 12:35PM
    Mansvi wrote:Please correct me where ever i am wrongAs per my understanding, when we submit LOV as item with a simple checkbox, shouldn't return value get mapped to apex_application.g_f01 variables ?am i missing something ? I am trying to insert data based on this assumption only.

    This is a checkbox page item, not a "simple checkbox". In APEX terminology a "simple checkbox" is only a display option for columns in a tabular form (a legacy component in 5.1). It is "simple" because it eliminates the normal complexity inherent in HTML where only checked checkboxes are included in page submission, and returns a value for every row in the form irrespective of checkbox state.

    Checkbox page items representing 1:M relationships should be processed as described in this thread. In APEX 5.1 the shuttle value can be accessed directly in DML using apex_string.split and a table expression: STRING_TO_TABLE function deprecated

    Manu1Manu1Shilpi Pauranik-Oracle
  • Manu1
    Manu1 Member Posts: 15 Red Ribbon
    edited Jul 11, 2017 12:28PM

    Thanks for providing more clarity over it. Now any idea what I am doing wrong here ?

    Button has action --> Dynamic action

    This dynamic action --> On true -> pl/sql block that is supposed to insert value of global variable in table.

    Except checkbox does not feed value to global variable .. something silly I must have done. Any pointers ?

  • Manu1
    Manu1 Member Posts: 15 Red Ribbon
    edited Jul 11, 2017 12:33PM

    The code:

    begin 

    apex_debug.message('Value of array f01 count '||APEX_APPLICATION.G_F01.count );

    FOR i in 1 .. APEX_APPLICATION.G_F01.count LOOP

        INSERT INTO DR_DRILL_ACTIONS

          SELECT SYSDATE,

                 APEX_APPLICATION.G_F01(i),      -- For every iteration, I am inserting this value to a table.

                 'PRECHECKS',

                 'STARTED',

                 NULL                           

            FROM DUAL;

    commit ;

      END LOOP;

    end;

    Any references for checkbox implementation like this ?

  • Manu1
    Manu1 Member Posts: 15 Red Ribbon
    edited Jul 11, 2017 2:50PM

    Still I am not able to understand what is wrong with the maping of checkbox and global variables.

    But yes, your suggestions did help.  Used string_to_table function to convert colon separated checkbox string to segregated values ready for insert and bingo! it started working.

    That would be one way of doing it and my concepts are still messy. But then, my code has started working now.  Thanks

    I will still wait to see if anyone can help me understand more how global variables work in conjunction with checkbox. I gotta use them in lot of places.

  • Pavel_p
    Pavel_p Member Posts: 2,312 Gold Trophy
    edited Jul 12, 2017 5:13AM Accepted Answer

    Hi,

    you mixed together few things. You created a page item PX_CHECKBOX and trying to reference APEX_APPLICATION.G_Fxx arrays (you chose g_f01 but there are 50 of them at your disposal). There is absolutely no relation between your PX_CHECKBOX page item and APEX_APPLICATION.G_Fxx thus there is no reason why APEX_APPLICATION.G_F01.count should return anything else than 0. Please, read the documentation to APEX_ITEM CHECKBOX2 Function .

    Let's have a following example:

    Create a Classic/Interactive report based on the select in documentation (do not forget to set the Escape Special Characters attribute of your Select column to No)

    SELECT APEX_ITEM.CHECKBOX2(1,empno,'CHECKED') "Select",--p_idx parameter here is 1  ename, jobFROM emp

    and add a Submit button. In this case is the p_idx (Number that determines which APEX_APPLICATION global variable is used. Valid range of values is 1 to 50. For example 1 creates F01 and 2 creates F0)  parameter = 1, so ONLY CHECKED values will be stored in G_F01 array after page submission (if do not select any of them, g_f01 count will be still 0).

    If you used APEX_ITEM.CHECKBOX2(2,empno,'CHECKED') "Select" in your select statement, checked values would be stored in G_F02 array etc.

    Hopefully now it's clear why your g_f01 contains 0 elements.

    Regards,

    Pavel

  • Manu1
    Manu1 Member Posts: 15 Red Ribbon
    edited Jul 12, 2017 12:09PM

    Makes sense. Will try few things out and see.

    Thanks

This discussion has been closed.