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