user3140792
user3140792

Reputation: 71

Do I need LockService getScriptLock if my script has many users

My html form uploads data to a spreadsheet with a Google script. I use the following function to prevent a conflict, since many users are accessing the web app page:

function lockservice() {
  var lock = LockService.getScriptLock();
  lock.waitLock(30000);
  lock.releaseLock();
}

I have another script to retrieve the data (separate script), that also has many users accessing it. So do I need getscriptlock for that also?

In another words, is there a conflict between users occuring when getting the data or only when uploading it? or maybe in both cases.

Upvotes: 1

Views: 328

Answers (2)

user16586520
user16586520

Reputation: 11

I have actually have the same understanding but:

I have a script where Lock Service is used and the locked section also includes a appendRow() operation to the sheet. The script allows up to 30 concurrent executions.

Despite knowing that appendRow()is stated to be atomic, I now experience that appendRow() actually may overwrite the last used row on a sheet!

I never experienced this behavior without making use of the Lock Service.

Anybody else observed this unexpected behavior?

In the linked screenshot you see the new Date() value of the previous record being replaced instead of an entire new row being appended below.

Any thoughts & suggestions to overcome this behavior are highly appreciated.

Screenshot: appendRow() replaces last row of sheet:

Screenshot: appendRow() replaces last row of sheet

Upvotes: 1

Alan Wells
Alan Wells

Reputation: 31310

If you are writing data to the spreadsheet with:

sheet.appendRow(array);

then you don't need Lock Service to write data. If you are using:

sheet.getRange().setValues(array_2_D);

Then you do need Lock Service.

So, appendRow() is "atomic" and setValues() is not. Atomic meaning that each operation runs completely independent from each other.

https://developers.google.com/apps-script/reference/spreadsheet/sheet?hl=en#appendRow(Object)

Getting values should use Lock Service if you have concurrent users. There is also a quota limit for concurrent users. The limit for "Simultaneous Executions" is 30, (at the time of this post)

https://developers.google.com/apps-script/guides/services/quotas#current_limitations

Upvotes: 3

Related Questions