title: Dependable dropdown and getValues() 2D array
body: <p>I am building dependable (filtered) dropdown in google sheet, where value in the one dropdown list depends on the choice of another. Although being a releatively simple arrangement, I came across the problem with <a href="https://developers.google.com/apps-script/reference/spreadsheet/range#getvalues" rel="nofollow noreferrer">getValues()</a>
  which returns 2D array.</p>
  
  <p>There is the following set up:</p>
  
  <ol>
  <li>Two sheets, one <strong>Activity</strong> and another <strong>$SheetData</strong>.</li>
  <li>Column E of the <strong>Activity</strong> contains dropdowns, which when selected, should provide appropriate choice in the column G.</li>
  <li>The data for Column E is sourced from sheet <strong>$SheetData</strong> (E1:K1);</li>
  <li>The data for Column G is sourced from sheet <strong>$SheetData</strong> from each of the respective columns (E1 = SIRE: SIRE1, SIRE2 etc);</li>
  <li>When SIRE is selected in Col E of <strong>Activity</strong>, I need the data in column G to be from E2:E of the <strong>$SheetData</strong>
  Here is my code:</li>
  </ol>
  
  <pre><code>function dependableDropdown() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var activity = ss.getSheetByName("Activity");
    var sheetData = ss.getSheetByName("$SheetData");
    var activeCell = activity.getActiveCell();
  
    if(activeCell.getColumn() == 5 &amp;&amp; activeCell.getRow() &gt; 1){
      activeCell.offset(0, 2).clearContent().clearDataValidations();
  
      var inspectionTypes = sheetData.getRange(1, 5, 1, 7).getValues();    
  
      var selectedValue = activeCell.getValue();
      var inspectionTypesIndex = inspectionTypes[0].indexOf(selectedValue) + 1;
  
      var validationRange = sheetData.getRange(2, inspectionTypesIndex, sheetData.getLastRow());
  
      var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
      activeCell.offset(0, 2).setDataValidation(validationRule);
    };
  };
  </code></pre>
  
  <p>Value returned by <code>inspectionTypesIndex</code> seems to be correct (SIRE = 1, OVID = 2 etc), but when I select data in Col E, I get the wrong data fed into the column G.</p>
  
  <p>Apprecaite your help.<br>
  Thank you, </p>
  
  <hr>
  
  <p>Corresponding screens:</p>
  
  <p><strong><em>Activity sheet</em></strong><br>
  <a href="https://i.stack.imgur.com/CdGOk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CdGOk.jpg" alt="Activity sheet"></a></p>
  
  <p><strong><em>$SheetData</em></strong><br>
  <a href="https://i.stack.imgur.com/s5hDB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s5hDB.jpg" alt="Data sheet"></a></p>