title: In Google Sheets onedit function, abort function if variable cell value is not blank
body: <p>I have a search page driven by checkboxes and an onEdit function in a Google Sheet. It allows users to search a dataset, select a single row (record) from the search results, and append a user code if assuming responsibility for that record. It includes a dialog box asking them if they wish to proceed before the function executes. If yes, it proceeds and resets. If no, it aborts and waits for a new command.</p>
  <p>The data setup is:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Col A</th>
  <th>Col B</th>
  <th>Col C</th>
  <th>Col D</th>
  <th>Col E</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Chkbox</td>
  <td>Name</td>
  <td>Age</td>
  <td>Place</td>
  <td>User</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The user code data enters in column E of the dataset. What I need is for the onEdit function to abort if another user has already assumed responsibility for that record. In other words, say User A searches and selects a record for &quot;Sarah Stout,&quot; and clicks the checkbox to code that as &quot;USER A&quot; to take responsibility for Ms. Stout (and USER A will appear for anyone else's subsequent searches). However, User B has already done the same thing, so in column E, it already says USER B. I want the function to abort so that User A override that from the search page.</p>
  <p>I tried:</p>
  <blockquote>
  <p><strong>if (NOT(ISBLANK($E$6))) return;</strong></p>
  </blockquote>
  <p>because the first search result would appear in row 6 (but the first row with a checkbox), but that didn't work. I just don't understand the syntax as well in this, so I don't know how to specify the column. Here's the onEdit code</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function onEdit(e) {
  if (e.range.columnStart != 1) return;
  if (e.value != 'TRUE') return;
  var sheet = SpreadsheetApp.getActive();
  var ignored_sheets = ['Sheet2','Sheet3','ReportOutput'];
  if (ignored_sheets.includes(sheet.getName())) return;
  var row_index = e.range.rowStart;
  var row = sheet.getRange('B' + row_index + ':D' + row_index).getDisplayValues().flat();
  if (row[1] == '') return;
  var result = SpreadsheetApp.getUi()
  .alert("Do you wish to mark this record?", SpreadsheetApp.getUi().ButtonSet.OK_CANCEL);
  if (result != SpreadsheetApp.getUi().Button.OK) {
  sheet.toast("Request canceled.");
  sheet.getActiveCell().setValue(false);
  return;}
  sheet.toast("Request initiated.");
  sheet.getActiveCell().setValue(false);
  sheet.getRange('B3').clearContent();
  sheet.getSheetByName('ReportOutput').appendRow(row);
  sheet.getSheetByName('Sheet1').setActiveCell('B3');
  }</code></pre>
  </div>
  </div>
  </p>
  <p>Does anyone have any ideas on how to make this work?
  Where am I going wrong?</p>
  <p>I know I'll need an IF statement, and I know I'll need something like this if they check the box when they shouldn't:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>    {sheet.toast("Unable to overwrite data.");
      sheet.getActiveCell().setValue(false);
      return;}</code></pre>
  </div>
  </div>
  </p>