0
votes

I have a script trying to identify if "HRZ" is found in Column F18:F, but it doesn't seem to work... It never identifies "HRZ" even if that is all thats in the column... Anyone able to help?

function exportNotifyHinges() {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Hinge'); //source sheet
  var testrange = sheet.getRange('F18:F'); //range to check
  var testvalue = (testrange.getValues());
  var ui = SpreadsheetApp.getUi();

  var shouldExport = true;
  for (i=0; i<testvalue.length;i++) {
    if ( testvalue[i] != "HRZ") {
      var response = ui.alert("Vertical conformance data identified in report. \n\n Do you want to cancel the export?",ui.ButtonSet.YES_NO);
      Logger.log(response);
        
      if (response == ui.Button.YES) {
        SpreadsheetApp.getActive().toast("Export Cancelled...");
        shouldExport = false;
        }
      break;
    }
  }
1
Please share a view only copy of your sheet.JohnA
What do you see if you log testvalue[i] to the console? Do you see a string? Or maybe something else - such as an array of data [ ... ]?andrewJames
It's in the ExportHinges.gs docs.google.com/spreadsheets/d/…Jon Bowles
Side note: I would also recommend using === and !== in preference to == and != - background.andrewJames
@andrewjames 7:31:57 AM Info [HRZ]Jon Bowles

1 Answers

1
votes

The key here is to use the debugger and inspect the array testvalues

enter image description here

This reveals each element is a 2 dimensional array, so change this line of code

if ( testvalue[i] != "HRZ") {

to this and it works fine

if ( testvalue[i][0] != "HRZ") {