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