I am trying to remove all protections on a range. I created a script that adds a protection when a user pushes a button. If the user pushes the button twice, it adds the protection twice. I came up with this script, mostly through recording macros, to remove the protection, but it only removes one protection. If a user pushes the button twice, this button only removes one protection and leaves the other protection (thus, leaving the range protected when it shouldn't be). Any advice on how I can remove ALL protections on the range?
var allProtections = spreadsheet.getActiveSheet().getProtections(SpreadsheetApp.ProtectionType.RANGE); var matchingProtections = allProtections.filter(function(existingProtection) { return existingProtection.getRange().getA1Notation() == 'C4:F30'; }); var protection = matchingProtections[0]; protections.remove();