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