Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

The edge cases that break simple Google Apps Script automations

Описание и применение

Короткие скрипты Apps Script, перемещающие строки при статусе "Done", часто теряют данные из‑за гонки при одновременных правках. Использование LockService и сканирование листа снизу вверх гарантирует надёжное перемещение всех строк.

Задача

Simple Google Apps Script row‑moving scripts often lose data or behave incorrectly in real sheets.

Результат

The updated script reliably moves all completed rows, even when multiple edits happen in rapid succession, and avoids data loss.

Рабочий процесс

  • 1. Trigger onEdit(e).
  • 2. Acquire LockService.getDocumentLock().
  • 3. Rescan the entire sheet from bottom to top for rows where status is "Done".
  • 4. Move each found row to the destination sheet using range.moveTo().
  • 5. Release the lock.

Доказательства

Set two rows to Done within a second and both triggers run at once. The first deletes its row, so the second one's row number now points at the wrong row.

Источник

Fix: take LockService.getDocumentLock(), then rescan the whole tab bottom‑up for Done rows instead of trusting e.range.getRow().

Источник

  • Дата записи: 2026-11-01T06:29:24.179Z