---
title: "Manage Google Form onFormSubmit script executions with Script Lock"
author: "Phil Bainbridge"
date: 2024-01-16T21:16:33+00:00
modified: 2024-01-16T21:17:17+00:00
canonical_url: https://pulse.appsscript.info/p/2024/01/control-google-form-submissions-script-executions-with-script-lock/
markdown_url: https://pulse.appsscript.info/p/2024/01/control-google-form-submissions-script-executions-with-script-lock.md
categories:
  - "Beginner"
  - "Forms"
  - "Snippet"
tags:
  - "pbainbridge.co.uk"
featured_image: https://pulse.appsscript.info/files/2024/01/LockServicecodesnippet.png
description: "Here's a nice post if you are having issues with concurrent executions in your Apps Script project. In the contribution for Phil Bainbridge you can learn about Script Locks and avoiding issues if you are using onFormSubmit triggers with simultaneous Google Form submissions. Personally I always struggle to remember how to use the Lock Service so examples like this are a great reminder."
---

# Manage Google Form onFormSubmit script executions with Script Lock

![Manage Google Form onFormSubmit script executions with Script Lock](https://pulse.appsscript.info/files/2024/01/LockServicecodesnippet.png)

> Use the Apps Script Lock Service to control Form submissions and prevent data loss
> [https://www.pbainbridge.co.uk/2023/11/control-form-submissions-with-script.html](https://www.pbainbridge.co.uk/2023/11/control-form-submissions-with-script.html)Lock Service code snippet

The following Google Apps Script is a one example of how the Lock Service can be used to prevent concurrent running of code. Here we have a Google Form that can be submitted by users at any point, the code then takes some of those details and appends them to another Google Sheet row. In normal circumstances this will happen relatively quickly and without clashes, but what if multiple people submit the Form at the same time!?

[Editor note: An alternative approach to `tryLock()` is `waitLock()`. The only different with a `waitLock()` is it will throw an exception after the set number of milliseconds. An example of `waitLock()` with `onFormSubmit` is included in [the reference documentation**](https://developers.google.com/apps-script/reference/lock/lock)]

Source: *[The Gift of Script: Control Form submissions with Script Lock*](https://www.pbainbridge.co.uk/2023/11/control-form-submissions-with-script.html)

---

*Published by [Phil Bainbridge](https://pulse.appsscript.info/p/author/phillipbainbridge/) on [Pulse](https://pulse.appsscript.info/). Original article: [https://pulse.appsscript.info/p/2024/01/control-google-form-submissions-script-executions-with-script-lock/](https://pulse.appsscript.info/p/2024/01/control-google-form-submissions-script-executions-with-script-lock/)*
