Lou
Lou

Reputation: 2509

Reset checkboxes to false - implemented solution not working

I have a column of checkboxes which the user can set to true or false - I want to run a Google Apps Script on the click of a button which resets the value of all the checkboxes to False.

I found a related question, and attempted to implement the solution from the accepted answer. Unfortunately, it doesn't seem to work as intended, and I don't know enough about Apps Script to understand why. Here is my code (barely modified from Tanaike's solution):

function resetBoard() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var dataRange = sheet.getRange('L5:L');
  var values = dataRange.getValues();

  for (var i = 0; i < values.length; i++) {
    for (var j = 0; j < values[i].length; j++) {
      if (values[i][j] == true) {
        values[i][j] == false;
      }
    }
  }

  dataRange.setValues(values);
}

Here is the sheet - the checkboxes in Column L are the ones I'm trying to reset. After I press the button to execute the script, it says that the script is finished, but nothing has changed:

enter image description here

Is there a simple mistake that explains why this isn't working?

Upvotes: 1

Views: 1407

Answers (1)

Tanaike
Tanaike

Reputation: 201428

Here is my understanding:

  • You want to change the checkboxes of the cells "L5:L" to false.
  • You want to achieve this using Google Apps Script.

Modification points:

  • In your script, values[i][j] == false; is required to be modified. In this case, values[i][j] is compared with false. So when you use this script, please modify to values[i][j] = false;.
  • In this case, when resetBoard() is run, how about unchecking all checkboxes of "L5:L"?

Modified script:

function resetBoard() {
  SpreadsheetApp.getActiveSheet().getRange('L5:L').uncheck();
}

Reference:

Upvotes: 2

Related Questions