1031
Views
12
Comments
Solved
GetForUpdate

I want to stop deleting record which is currently accessed using GetForUpdate.

Please check the following scenario. The record with the name Alan is accessed by using the GetPersonForUpdate action but still, but I am able to delete this record.  

This record should not be deleted using the DELETE button from the table as it is currently accessed using GetForUpdate.

The record that is in update state shall not be deleted from table using delete button. 



screenshot-personal-5238fesh.outsystemscloud.com-2023.03.02-11_28_24.png
GetForUpdate.png
2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

@Pramod Prakash Ghogare ,

in your screenprints you show an action doing a GetForUpdate, and then no actual updates inside that action.  

If after that action flow, you return to the screen and hope that the lock will remain in place until your user presses the Save button, you have a wrong understanding of the GetForUpdate.

It only holds the lock as long as you are inside the same transaction.  So end of transaction = end of GetForUpdate lock.

Now for what a transaction is and when it ends, depends, but in it's most simple form (and as you are doing the OSMDB exercise, that's the case, I think) the transaction starts at the first database access inside a server action, and ends right before the server sends the resulting page back to the browser.

So by the time your record is shown to the end user for him to edit, that transaction and the lock on the record is long gone.

Dorine

2024-03-22 09-17-23
Chandra Vikas Sharma
Solution

Hi Pramod,

GetForUpdate action locks the record in the database until the transaction is finished, preventing other processes from accessing this record . i e we are using GetForUpdate insted of CreateOrUpdate  action.



2023-01-05 15-10-23
Pramod Prakash Ghogare

Thanks for your reply,

but why do we need if condition as its own capable to lock the record?

2024-03-22 09-17-23
Chandra Vikas Sharma

Hi Pramod ,

You just need to add if condition before the Getforupdate action and  compare the user identifier and if it's true the do not do anything and if condition is false the you can delete the record.


if any confusion send me OML so i can do.



    


2023-01-05 15-10-23
Pramod Prakash Ghogare

If I am setting the condition manually then what is the meaning of using GetForUpdate as it can be done with the CreateOrUpdate action having if condition prior to it? 

What is the meaning of following

GetForUpdate: Reads an entity record from the Database through its identifier and prevents other requests from accessing it until it's updated.



2024-03-22 09-17-23
Chandra Vikas Sharma
Solution

Hi Pramod,

GetForUpdate action locks the record in the database until the transaction is finished, preventing other processes from accessing this record . i e we are using GetForUpdate insted of CreateOrUpdate  action.



2023-01-05 15-10-23
Pramod Prakash Ghogare

Thanks for your reply,

but why do we need if condition as its own capable to lock the record?

2024-03-22 09-17-23
Chandra Vikas Sharma

Hi Pramod,

 lock record means if at the time of GetForUpdate  opration any one wants to update on that record same time then this action prevent this type of scenario.


2024-03-22 09-17-23
Chandra Vikas Sharma

if need more explanation then please read below outsystem documentation.


https://success.outsystems.com/documentation/how_to_guides/data/how_to_handle_concurrent_updates_on_application_data_records/

 

2020-09-21 11-35-56
Sachin Waghmare

Hello Pramod,

Based on your screenshots it looks like you are using 2 different buttons and actions for performing these 2 different operations (Update and Delete). So, first a record is getting updated and then you are deleting the same record using that entity identifier. So, in this case GetforUpdate action will not stop you to delete that record, since you are not doing at the same time.

Thanks,

Sachin

2023-01-05 15-10-23
Pramod Prakash Ghogare

can you tell me how to do it at the same time?

2020-09-21 11-35-56
Sachin Waghmare

I am not sure if you are aware of the concepts of locks in traditional languages, if not please refer the below link.

https://learn.microsoft.com/en-us/sql/ado/guide/data/types-of-locks?view=sql-server-ver16

The same concept applies here as well. If 2 user tries to perform operation on same record it will not allow the second one until first one's transaction get completed. So, getforupdate action will lock the record for second user and does not allow to make any update. This scenario happens in multi user environment.

2023-01-05 15-10-23
Pramod Prakash Ghogare

I retrieved the record from getforupdate action then it should not allow to update / delete until getforupdate action release the record


2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

@Pramod Prakash Ghogare ,

in your screenprints you show an action doing a GetForUpdate, and then no actual updates inside that action.  

If after that action flow, you return to the screen and hope that the lock will remain in place until your user presses the Save button, you have a wrong understanding of the GetForUpdate.

It only holds the lock as long as you are inside the same transaction.  So end of transaction = end of GetForUpdate lock.

Now for what a transaction is and when it ends, depends, but in it's most simple form (and as you are doing the OSMDB exercise, that's the case, I think) the transaction starts at the first database access inside a server action, and ends right before the server sends the resulting page back to the browser.

So by the time your record is shown to the end user for him to edit, that transaction and the lock on the record is long gone.

Dorine

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.