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

Returns a lock shared by all runs of the script.

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

Better Sheets tutorials

No tagged tutorials yet. Fetch Apps Script from the harvest table and this page fills automatically.