A form response is already in row 3 when another submission arrives in row 4. If both handlers call getLastRow(), both can end up looking at row 4. Adding a lock around that lookup makes them wait for each other. It does nothing to tell the second execution which submission it owns.
For an installable spreadsheet form-submit trigger, two pieces of information serve different purposes:
-
e.range.getRow()identifies the response that fired this event. -
LockService.getScriptLock()protects a shared operation, such as choosing the next ticket number.
In a small practice sheet, put Timestamp, Subject and Ticket ID in row 1. Put an existing ticket numbered 20 in row 2. Leave the ID cells empty for the blue-projector request in row 3 and the green-projector request in row 4.
| Event handled | Row 3 ticket | Row 4 ticket |
|---|---|---|
| Row 4 first | empty | 21 |
| Then row 3 | 22 | 21 |
| Replay row 4 | 22 | 21 |
Each timestamp stays where Forms wrote it. The numbers tell you which ID was allocated first. They need not match the order in which requests arrived.
Look up the two symbols offline
The worked handler and its small Zeal/Dash feed include this exact replay. In Zeal, open Docset Library → Add feed and paste the linked XML address. After installation, try:
- Search
gaslock:e.rangeand read which type of trigger provides the row. - Search
gaslock:getScriptLockand follow Open the complete handler. - Select the code inside the text box and copy it. The separate replay page has the starting rows and the expected result.
The handler locates the dedicated Ticket ID header. It checks for duplicate IDs, formulas and invalid values while holding the lock. A retry sees the ID already assigned to that row and leaves it in place. On a new write, it calls SpreadsheetApp.flush() before releasing the lock.
If the lock times out, inspect the failed execution and the blank ID. The example does not schedule its own retries. If you attached the trigger to the form itself, its event shape is different; use the linked spreadsheet's form-submit trigger for this exercise.
