I have a spreadsheet from last year and it worked OK then. Without edits, I opened it and now it throws this execution error:
Exception: The parameters (SpreadsheetApp.Range,number,(class)) don't match the method signature for SpreadsheetApp.Range.copyTo.
This line with error it points to is:
validationSource.copyTo(validationDestination, SpreadsheetApp.CopyPasteType.PASTE_DATA_VALIDATION, false);
I can confirm that both validationSource and validationDestination are variables of class Range from .getRange().
What I don't understand:
- Why it worked before and now it doesn't without the code getting edited.
- Why the exception says:
(SpreadsheetApp.Range,number,(class)).falseis not a class,falseis a boolean value.
I even tried to coerce a boolean value, just in case, with:
validationSource.copyTo(validationDestination, SpreadsheetApp.CopyPasteType.PASTE_DATA_VALIDATION, 1==0);
and still the same error.
Now I'm wondering if this is a Google Apps Script bug.
References:
- https://developers.google.com/apps-script/reference/spreadsheet/range#copytodestination,-copypastetype,-transposed
- https://issuetracker.google.com/issues/453396596
Example code:
function onEdit(e) {
for (let c=1; c <= e.range.getNumColumns(); c++) {
for (let r=1; r <= e.range.getNumRows(); r++) {
let cell = e.range.getCell(r, c);
let validationSource = e.source.getSheetByName("Lists").getRange("A1");
let validationDestination = e.source.getSheetByName("Ratings").getRange(cell.getRow(), cell.getColumn()+3);
if ( cell.getValue() ) {
validationSource.copyTo(validationDestination, SpreadsheetApp.CopyPasteType.PASTE_DATA_VALIDATION, false);
} else {
validationDestination.setDataValidation(null).clearContent();
}
}
}
};