Waits until the lock is available, then acquires it.
class LockService method .waitLock()
LockService is the Apps Script service.
.waitLock() is the method name you will see after a dot in your code.
What it does
Why it's used
- Queue up work until the previous run finishes.
- Safer than crashing when two executions collide.
Common errors
- Forgetting parentheses on waitLock. Write LockService.waitLock(), not LockService.waitLock or waitLock by itself.
- Skipping dots between chained calls. Each step needs a dot, like LockService.waitLock().
- Adding spaces where they do not belong. Write LockService.waitLock(), not LockService .waitLock(), LockService.waitLock (), or LockService . waitLock().
- Wrong capitalization. Use LockService and waitLock, not lockservice or waitlock.
Explore
Related methods
-
.tryLock()
Tries to acquire the lock without waiting.
-
.releaseLock()
Releases a lock so other script runs can continue.
-
.getUserLock()
Returns a lock private to the current user.
-
.getDocumentLock()
Returns a lock tied to the current spreadsheet or doc.
-
.getScriptLock()
Returns a lock shared by all runs of the script.
More Apps Script
Better Sheets tutorials
No tagged tutorials yet. Fetch Apps Script from the harvest table and this page fills automatically.