How to Insert a Primary Key (Auto-Incremented) into Multiple Tables from one Page

I am creating a Master Record with many Children (normalizing the database). I am using a MariaDB. All relationships have been created (foreign keys). The master record has a primary key that is auto-incremented.

The form is designed with many accordions. Each accordion component updates a separate table that uses the Primary Key of the Master table. I know that I will need to create a succession of insert statements, one for each table I am updating.

In Wappler, how and where would I grab the Primary Key from the initial insert (after the DB assigns the auto-incremented value) and grab it to be used in the subsequent inserts (into the children tables)?

I believe you are looking for the identity returned by the first insert step.

Yes, Jon. I believe there is a command and Syntax to add in some Wappler field to accomplish this. I just don’t know where it is to be placed and what the command would be.

Hi Bruce,

Not sure if this advice will help, as it depends on how exactly it is all set up for you in Wappler.

If you have a server action file, say with 2 steps, and INSERT and then another INSERT or UPDATE, you can see in this screenshot below how you would use the PK auto-generated from the first insert to use in the update or insert of the 2nd step (by clicking the lightning bolt in the Value column):

I have only used this before when all the steps are the the same server connect action file so that it flows quite sequentially.

As far as the code/syntax, it seems to be:

insertBusiness.identity

Hope this helps.

2 Likes

HI Phillip. This makes sense. When I get to that point I will try this.

Thank you

Teodor, did you have something to add? I saw you responded but no text appears.

I think you’ll find the notification was because he ‘liked’ my response.

Likes and replies both show up as notifications on one of your own posts.

1 Like