Announcement

Collapse
No announcement yet.

how to print the record id on control application directlyAFterInsert!?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to print the record id on control application directlyAFterInsert!?

    hi guys, simply, i have a form that has internal ID auto incremant - mysql - all works ok, i want to display a control page with the fields that was entered... I could show all fields ok onAfterInsert sc_redir to control application with global variables... but the ID is going as "0" it should go normal as the record is created actually in the database, why I can't show it onAfterInsert event so the user knows his record id number is XXX ? I wounder if it is a bug or there is a trick we must follow?

  • #2
    Go to Application -> Navigation -> Return After Inserting = Yes

    There you have it, no need to redirect somewhere.

    jsb

    Comment


    • #3
      hi sir

      but i want to redirect to control application so to give the record ID that was created by entry and also want to add some links to user for where to go next

      the id is not yet created when first adding the values of the form, but it supposed to be created when AfterInsert hence we are supposed to be able to show the record id when redirecting after the record is added to db, i just don't understand, i was reading in the forums that should reserve the id or use sequence but couldn't really understand about sequence or how to reserve ID or how to show it after the insert in a control application, still dull to me

      Comment


      • #4
        Why all this punishment. :-)

        onAfterInsert
        sc_commit_trans();
        [new_id] = {id_field};
        sc_redir(your_control_app);

        Control application onLoad
        {id_field} = [new_id];

        jsb

        Comment


        • #5
          I know its punishment boss yet i have to add in that control applications many different links and stuff

          but the id still not going correct, i have other data from the same record like name, class, category... all goes ok with sc_redir as parameters but the id is going as "0" showing in the control like id: 0 and name OK class OK category OK..etc.

          i use the same form in edit mode and it sends the id number ok to control (onAfterUpdate event)... only in case of first creation of the record (insert) it sends the id: 0, so i thought it is not created yet in the database in onAfterInsert? but obviously it does, and the record is added to db, so the onAfterInsert event should send the id that was created by auto increment and show to user along with the other values!

          strange

          any hint?

          Comment


          • #6
            Milke,

            If you are using MySQL, you can do like this in AfterInsert:


            Code:
            sc_commit_trans();
            sc_lookup(sc,"SELECT LAST_INSERT_ID()"); 
            sc_redir(control_app,new_id=$sc[0][0]);
            Just be careful to not specify the table name in your query, "SELECT LAST_INSERT_ID() FROM ZOTTO" will return the same ID, once for every record in the table ZOTTO.
            If you are not using MySQL, then your database of choice should have something similar.

            Dave
            Dave Prue
            Code Whisperer
            Lahar International Corp
            www.lahar.net

            Comment


            • #7
              YES dave, that works, i wounder why onAfterInsert why doesn't go as normal field as it is created (onAfterInsert) self explainatory!

              this is ok

              Code:
              sc_commit_trans();
              sc_lookup(sc,"SELECT LAST_INSERT_ID()"); 
              [id]={sc[0][0]};

              thanks dude

              Comment


              • #8
                Hi,

                I have a similar issue, maybe you can help me.

                i want to insert in another table the id after my form is fill. but i have the same always send value '0' im using onafterinsert event.

                Comment


                • #9
                  Hi steph07

                  it is the same as above

                  look at the code examples that comes with SC right panel, insert on another table, and add this value to the array [id] to be added to your another table, or even you can set {sc[0][0]} directly, it will send to your another table accordingly

                  Code:
                  sc_commit_trans();
                  sc_lookup(sc,"SELECT LAST_INSERT_ID()"); 
                  [id]={sc[0][0]};

                  Comment

                  Working...
                  X