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