4 Replies Latest reply: Jan 7, 2013 9:26 AM by 714270 RSS

    Column value Increment on add row button of tabular form

    Vedant
      Hi,

      I am working on apex 4.1.

      I am working of tabular form.

      mY table name is ACT_SEG
      My primary key column name is LINE_ID NUMBER TYPE.


      On custom pl/sql function i have written code
      declare
      abc number;
      begin
      select NVL(max(line_id),0)+1 into ABC from ACT_SEG;
      return abc;
      end;
      I want to increment mY LINE_ID COLUMN ON ADD ROW BUTTON of tabular form.

      But it is Incrementing on submit button.

      After inserting one row how i can increment my LINE_ID ON add_row button.


      Thansk & Regards
      Vedant
        • 1. Re: Column value Increment on add row button of tabular form
          714270
          Vedant wrote:
          Hi,

          I am working on apex 4.1.

          I am working of tabular form.
          Is it a manual tabular form or wizard generated one?
          mY table name is ACT_SEG
          My primary key column name is LINE_ID NUMBER TYPE.


          On custom pl/sql function i have written code
          declare
          abc number;
          begin
          select NVL(max(line_id),0)+1 into ABC from ACT_SEG;
          return abc;
          end;
          I want to increment mY LINE_ID COLUMN ON ADD ROW BUTTON of tabular form.

          But it is Incrementing on submit button.
          What does your "ADD ROW" button do? Does it submits the page or just calls the javascript:addRow()?
          After inserting one row how i can increment my LINE_ID ON add_row button.
          A similar issue has been discussed in the thread below:
          Add sequence to Tabular form Add Row?
          • 2. Re: Column value Increment on add row button of tabular form
            Vedant
            Hi,

            This is wizard generated form. and how i can do this with item or DB.

            Could you explain in detail.









            Thansk & Regards
            Vedant
            • 3. Re: Column value Increment on add row button of tabular form
              Vedant
              Hi,

              This is wizard generated form. and how i can do this with item or DB.

              Line_id is my PRIMARY_KEY COLUMN. There is no option for pass default item or function.

              Could you explain in detail.









              Thanks & Regards
              Vedant

              Edited by: Vedant on Jan 7, 2013 3:31 AM

              Edited by: Vedant on Jan 7, 2013 3:32 AM
              • 4. Re: Column value Increment on add row button of tabular form
                714270
                Vedant wrote:
                Hi,

                This is wizard generated form. and how i can do this with item or DB.

                Line_id is my PRIMARY_KEY COLUMN. There is no option for pass default item or function.

                Could you explain in detail.
                Since LINE_ID is your primary key column, I suggest that you create it in the database instead of writing JS code to populate your tabular form column.
                When you create the tabular form using the wizard, one of the steps is to select the primary key column and the next is to identify the method to populate the primary key. You get 3 options - Existing Trigger, Custom PL/SQL Function and Existing Sequence.
                You can choose any one of the 3 options. I think, you are currently using "Custom PL/SQL Function" option. This function will create the primary key value at the time of insert. Since, the Add Row button doesn't perform any database I/O (unless explicitly specified), you do not see the result of the pl/sql function. The "Submit" function calls the "ApplyMRU" process to perform the insert for new records. The custom pl/sql function is therefore, called to generate the primary key for you.

                Do you have any requirement to show to the users what primary key value will be generated when they hit the "Add Row" button? If yes, the option is to set default value for the column under Column Attributes -> Tabular Form Attributes -> Default Type and Default. An example is shown here:

                http://apex.oracle.com/pls/apex/f?p=46417:7

                So, if your function name is my_func(), you can have the Default Type as "PLSQL Expression or Function" and Default as the function name - my_func()

                But, I believe the default value is not re-computed every time. See Arie's comment in the thread below:
                Tabular form - Default Value


                Therefore, the better option would be to have the submit process handle the primary key creation.



                Hope the above explanation helps.