Retrieve record ID after insert

#1

After inserting a record how do I get the new record ID back so I can use to load a table?
I am working on a job manager type page where the user will create new jobs and then add tasks, comments, and upload files for that particular job.
Currently, I display a list of jobs created for the user and sort the jobID as a variable that is used to populate three other tables.
What I want to happen is after a new job is created the new jobID is passed back to the variable and the other tables reloaded.
The only part I can’t figure out how to do is to get the jobID back after inserting the record. I have tried adding the insert to a serverconnect and then getting the identity after inserting but that did not work. I also try using the identity in the server action to query the database using the identity in the same server action as the insert. That also didn’t work.

#2

This recent thread might be helpful. This from the docs should help too.

1 Like
#3

This video should help

2 Likes
#4

Try this post from George.

2 Likes
#5

Thanks for the help, this was what I was looking for.

#6

@Hyperbytes @George I have a multi-user scenario where there will be simultaneous inserts.
The MySQL docs say that last inserted id is accurate on per-connection basis.
So I just wanted to know if each call to server action creates a separate connection? I would assume so as we have to add the DB connection step in each server action.
OR, does the server create one single global connection and re-uses it on server action call?

#7

Yes each server connect call makes its own db connection, so there will be no multi user issues. This is how it is supposed to work.

Within the server connection action the db connection can be reused for the different steps - but that is normal as it is all for the same action and user.

1 Like