need assistance with this code for informing on fire alarms in my area.

Question

Hello, im part time hobby looking to revamp my skills in this but facing an error.
here is the code:

// want to use the below URL to fetch "Alarm level 0" and dump into google sheets


function updateAlarmLevelZero() {
  const url = "https://cohweb.houstontx.gov/ActiveIncidents/Combined.aspx?agency=F";
  
  const response = UrlFetchApp.fetch(url);
  const html = response.getContentText();


  // Extract table rows
  const rows = html.match(/<tr[^>]*>(.*?)<\/tr>/g);


  if (!rows) {
    Logger.log("No table rows found");
    return;
  }


  // Extract headers
  const headerCells = rows[0].match(/<t[hd][^>]*>(.*?)<\/t[hd]>/g)
    .map(cell => cell.replace(/<[^>]+>/g, "").trim());


  // Find Alarm Level column index
  const alarmIndex = headerCells.findIndex(h => 
    h.toLowerCase().includes("alarm")
  );


  if (alarmIndex === -1) {
    throw new Error("Alarm Level column not found");
  }


  const output = [];
  output.push(headerCells); // header row


  // Loop through rows
  for (let i = 1; i < rows.length; i++) {
    const cells = rows[i].match(/<td[^>]*>(.*?)<\/td>/g);
    if (!cells) continue;


    const cleanCells = cells.map(cell =>
      cell.replace(/<[^>]+>/g, "").trim()
    );


    // Filter Alarm Level = 0
    if (cleanCells[alarmIndex] === "0") {
      output.push(cleanCells);
    }
  }


  // Write to Google Sheet
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.clear();
  sheet.getRange(1, 1, output.length, output[0].length).setValues(output);
}

I then get met with an error: 

Error: Alarm Level column not found

updateAlarmLevelZero
@ Code.gs:27
 line27 is this one: throw new Error("Alarm Level column not found");

wonder if anyone gots any pointers

Posted Apr 9, 2026, 9:25 PM UTC

52
Loading comments…