How to handle invalid data caused by users making same change at same time

Lets say two users are at the same time making a change that decrements some count (maybe items in inventory). Each change would adjust that count to zero. Negative counts are not valid. If both users were making this change at the same time, as far as each device is concerned they are both making a valid change. The first user saves and the count goes to zero - all is ok. But the second user saves almost at the same time, the count in the data source goes negative and there is now a problem in the data.

This rare scenario doesn’t seem like it can be prevented up front when the app allows multiple users to change the same data. If there is, please let me know.

By the way, I do understand this is a common problem that has to be dealt with in any system where multiple users are changing the same data simultaneously.

So, I am wondering how some of you AppSheet developers might have or would react to this problem scenario so that it can be caught and corrected ASAP??

0 13 755
13 REPLIES 13

In your scenario it won’t go to negative value because the start situation is the same for both users. When they are doing the update at the same time, they are both starting for example from value 2.

Ah, yes. I keep forgetting about that part (I’ll blame it this time on being away for weeks on vacation!)

But what would happen in this scenario:

I’ve got 3 users looking at an app, each displaying that we’ve got 2 of something:

*User 1 orders 1 of the item
*User 2 orders 1 of the item
*User 3 orders both (seemingly available) items.

There needs to be something built into the system to flag user 3’s order and handle the fact that there is no available inventory.

Yes, great point! That is the main concern when the example app is an Order Placement app where available Inventory is critical (this is my actual use case). Obviously other app types might have other issues/concerns with similar data change scenarios and other apps may have no issue at all.

One option I can think of is running a Workflow as each record is entered or updated to validate values - in the Order placement app, validate available Inventory against open orders. An alert/message could go out to the user who entered/changed the offending record.

Another option, if time is not critical, is running a Report at the end of the day, notifying users of Inventory discrepancies.

Any other options?

I’ve come across this as well, and my solution was to implement a workflow that would flag orders that result because of this.

One workaround would be the sync check… if the last sync has happened more than few minutes ago, ask the user to sync before continue. It’s not protecting 100%, but it can help a lot.

How can you force a sync check… I’ve been asking for that for months! Well… the ability to force a sync is what I’ve been looking for actually.

Linking to a particular app and force a sync:

CONCATENATE(“MyApp-123#at=”, ENCODEURL(NOW())) will navigate to app “MyApp-123”, force a sync, and display its default starting view.

Hmm… have you ever tried implementing this as an action? So that you can “Call a sync?”

I tested it, and it worked… Not extensively…

In my case I had to use an expression like this:

CONCATENATE("MyApp-123#view=My_View&row=",[Key],"&at=",NOW() + 1)

Only the + 1 forced the sync. That was a tip from @LeventK

What I have used… add a virtual column with app formula NOW() and use that DateTime value for verification when the app was synced.

Everyone, this is a great suggestion to help automatically minimize out of sync data. I’ll look into starting to use this function. Obviously, we would only want to use this virtual column sparingly - in forms/views where it is critical to have the most up to date data. Users will get frustrated having to wait on syncs all the time.

And as @Aleksi has pointed out, the “auto-sync” function is not a 100% solution for the original posted problem and the issues that arise as discussed in the thread. So, I will likely implement a Workflow to check for issues and send an alert/email.

Top Labels in this Space