<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Noah Federovitch</title>
    <description>The latest articles on DEV Community by Noah Federovitch (@noah_federovitch_efc33693).</description>
    <link>https://dev.to/noah_federovitch_efc33693</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4214140%2F0db24d2b-0410-49d1-87fd-d22d7a9d2ad6.png</url>
      <title>DEV Community: Noah Federovitch</title>
      <link>https://dev.to/noah_federovitch_efc33693</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/noah_federovitch_efc33693"/>
    <language>en</language>
    <item>
      <title>The edge cases that break simple Google Apps Script automations</title>
      <dc:creator>Noah Federovitch</dc:creator>
      <pubDate>Thu, 29 Oct 2026 02:32:12 +0000</pubDate>
      <link>https://dev.to/noah_federovitch_efc33693/the-edge-cases-that-break-simple-google-apps-script-automations-mh8</link>
      <guid>https://dev.to/noah_federovitch_efc33693/the-edge-cases-that-break-simple-google-apps-script-automations-mh8</guid>
      <description>&lt;p&gt;Most "move a row when Status is Done" scripts you find online are about ten lines. They work in a demo and then quietly lose data in a real sheet. Here are the failures I hit while writing a few dozen of these, and the fixes.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Two quick edits leave a row behind
&lt;/h2&gt;

&lt;p&gt;The usual pattern is &lt;code&gt;onEdit(e)&lt;/code&gt;: if the edited cell says Done, move that row. 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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; take &lt;code&gt;LockService.getDocumentLock()&lt;/code&gt;, then rescan the whole tab bottom-up for Done rows instead of trusting &lt;code&gt;e.range.getRow()&lt;/code&gt;. A missed trigger gets picked up by the next edit, too.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;appendRow&lt;/code&gt; changes your data
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;appendRow(values)&lt;/code&gt; re-parses values, so a zip code like &lt;code&gt;02134&lt;/code&gt; becomes &lt;code&gt;2134&lt;/code&gt; and a formula becomes its result. Use &lt;code&gt;range.moveTo(destination)&lt;/code&gt;, which keeps values, formats and formulas exactly.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. You can't delete the last non-frozen row
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;deleteRow&lt;/code&gt; throws "not possible to delete all non-frozen rows" when the moved row is the last one under a frozen header. &lt;code&gt;moveTo&lt;/code&gt; already emptied the source row, so catch the error and leave the empty row in place.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The destination tab runs out of grid
&lt;/h2&gt;

&lt;p&gt;A new sheet has 1,000 rows and 26 columns. Writing to row 1,001 throws. Grow the grid with &lt;code&gt;insertRowsAfter&lt;/code&gt; / &lt;code&gt;insertColumnsAfter&lt;/code&gt; before you move.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Calendar events land on the wrong day
&lt;/h2&gt;

&lt;p&gt;A date cell arrives as an instant at midnight &lt;em&gt;in the spreadsheet's time zone&lt;/em&gt;. Pass it straight to &lt;code&gt;createAllDayEvent&lt;/code&gt; from a script running in a time zone further west, and the event lands on the day before. Format the day in the spreadsheet's zone (&lt;code&gt;Utilities.formatDate(date, ss.getSpreadsheetTimeZone(), 'yyyy-MM-dd')&lt;/code&gt;), then build the event time from that string.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Copied rows steal each other's events
&lt;/h2&gt;

&lt;p&gt;If you store the Calendar event ID in the row, a user who copies the row also copies the ID. Now two rows update one event. De-duplicate IDs top-down on every sync: the first row keeps the event, and copies get a new one.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. The 6-minute limit eats your progress
&lt;/h2&gt;

&lt;p&gt;Apps Script kills a run at 6 minutes, and a killed run skips your &lt;code&gt;finally&lt;/code&gt;, so IDs created so far are never written back. Stop yourself at around 4 minutes, save a resume point in &lt;code&gt;PropertiesService&lt;/code&gt;, and start the next run there. Wrap around, so the tail of a big sheet isn't starved.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. "Hide this tab" fails on the last visible tab
&lt;/h2&gt;

&lt;p&gt;Sheets won't hide the only visible tab. Compare tabs with &lt;code&gt;getSheetId()&lt;/code&gt;, not &lt;code&gt;===&lt;/code&gt;: two &lt;code&gt;Sheet&lt;/code&gt; objects for the same tab are different objects in Apps Script.&lt;/p&gt;




&lt;p&gt;I hit these while building a set of free, MIT-licensed scripts you can paste into your own sheet: &lt;a href="https://decodedxr.github.io/free-google-sheets-scripts/" rel="noopener noreferrer"&gt;Free Google Sheets scripts&lt;/a&gt;. They cover mail merge, Doc merge to PDF, Sheets to Calendar, Gmail to Sheets, row cleanup and more.&lt;/p&gt;

&lt;p&gt;If none of them fits, I also &lt;a href="https://decodedxr.github.io/free-google-sheets-scripts/custom-google-sheets-script.html" rel="noopener noreferrer"&gt;write custom ones&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>googleappsscript</category>
      <category>googlesheets</category>
      <category>javascript</category>
      <category>automation</category>
    </item>
  </channel>
</rss>
