Written by

Question Vivek Nayak · Aug 27, 2019

How to get last inserted RowID when %Save() function is used?

I need RowId of inserted record.

I have used below logic to get max row id,

but it will  not give desired result when multiple people enter record in the table at the same time.

Comments

Evgeny Shvarov · Aug 27, 2019

Hi Vivek!

Instead of &sql ... 

you can do:

write objExternalUser.%Id()
0
Vivek Nayak  Aug 27, 2019 to Evgeny Shvarov

So, If I am using objExternalUser.%Id() then which Id I ll get

1) Id of record inserted by my objExternalUser.%Save() function?

2) Id of latest inserted record?

0
Evgeny Shvarov  Aug 27, 2019 to Vivek Nayak

Sorry Vivek. My code provides you the Id of objExternalUser you save (possible create) above. It's 1).

It's not the latest inserted record. I thought you need:

I need RowId of inserted record.

Out of curiosity: why do you need the latest record?

0
Vivek Nayak  Aug 28, 2019 to Evgeny Shvarov

Thanks Evgency,

I got my answer, actually I need the Id of record inserted by my objExternalUser.%Save() function and that I got by your answer( objExternalUser.%Id() )

0
Yaron Munz · Aug 28, 2019

When you create a class that the IDs are maintained by the system (standard class without modifying the storage, then  there is a  save  mechanism to give a new ID to every new object that is being saved to the database.

Of course that when multiple users are saving new data simultaneously , a specific process ID after a %Save() might not be the last one in the table.

0