Saasu Integration Tip: Concurrent update control in Saasu

Concurrent update happens when a user is trying to update/delete a record that is being updated by another user at the same time in an application. This is very vital as it could cause a data integrity issue and maybe deadlock at the database level. Luckily, most of the applications available in the market nowadays have concurrent update control to prevent an unwanted disaster.


One good example that I will be discussing here is Saasu – one of the very popular cloud accounting applications.
Saasu is using an attribute called “lastUpdatedUid” (which contains a unique value for each record in Saasu) to keep track of the edit sequence and to prevents the concurrent update. The value of the “lastUpdatedUid” attribute will be changed whenever a record is updated by someone via Saasu application or programmatically through REST API call.
 You can find out the “lastUpdatedUid” for a record in Saasu by viewing the HTML source in the Edit page, the example that I’m using here is Edit Contact page.
You can also retrieve the value by retrieving the contact via REST API call. Here is the result that you will see in the response:
Here is a simple demo to simulate how to use the “lastUpdatedUid” when updating a contact via the REST API by using CURL and how Saasu prevents the concurrent update.
1. Create a contact in Saasu via REST API and this will return you a “lastUpdatedUid” in the response.
curl -X POST -d 'Mr.SmithJohn' ''
Response from Saasu:

2. Then, go to the Saasu application to make some changes to the contact and save it. Saasu will generate a new “lastUpdatedUid” for the contact record once the changes are saved.
3. Now, let’s try to update the contact by using the old “lastUpdatedUid” that returned by Saasu in Step 1. You can see that Saasu returned an error response saying that the contact has been updated by someone and the provided lastUpdatedUid is outdated.
curl -X POST -d 'Mr.SmithJohn' ''
Response from Saasu:

        Record to be updated has changed since last read.
        Netaccounts.Core.Exceptions.RecordHasChangedException: Record to be updated has changed since last read.
   		at Netaccounts.Ola.Bll.FileEntityManager.SaveInternal(FileEntity fileEntity, Boolean performSyncCheck)
   		at Netaccounts.Ola.Bll.Contact.SaveInternal(FileEntity fileEntity, Boolean performSyncCheck)
   		at Netaccounts.Ola.Bll.FileEntityManager.Save(FileEntity fileEntity, Boolean performSyncCheck)
   		at Netaccounts.Ola.Bll.Contact.Save(FileEntity fileEntity)
   		at Netaccounts.Ola.Rest.RestTasks.EntityTask`2.ExecuteInternal(TaskResult result)
   		at Netaccounts.Ola.Rest.RestTasks.UpdateTask`2.ExecuteInternal(TaskResult result)
   		at Netaccounts.Ola.Rest.RestTasks.Task.Execute()

In order to update the contact record correctly, I need to provide the latest lastUpdatedUid. Hopefully this gives you a basic idea on how Saasu handles the concurrent update 😀