I have the following code working perfectly as desired... It completes all the tasks as expected but still populates a red error box advising me of an Exception. It's definitely completing all of the tasks, so I can't tell what I've got wrong in here but maybe I'm just using the wrong syntax somewhere? I'd appreciate any help.
Error Message: Exception: The parameters (String) don't match the method signature for SpreadsheetApp.Sheet.activate
Here is a link to my example sheet
function AddRoutedOptions() {
var ui = SpreadsheetApp.getUi(); // Same variations.
var result = ui.alert(
'Add all Routed tasks to the Project Tracker?',
'Are you sure you want to add all Routed tasks to the Project Tracker?',
ui.ButtonSet.YES_NO);
// Process the user's response.
if (result == ui.Button.YES) {
// User clicked "Yes".
var pglc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Pre-Go Live Checklist');
var vcc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Video Course Checklist');
var rsc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Routed Setup Checklist').activate();
pglc.getRange('B32:B35').copyTo(pglc.getRange('E23:E26'), {contentsOnly:true});
vcc.getRange('B32:C37').copyTo(vcc.getRange('G10:H15'), {contentsOnly:true});
rsc.activate('Routed Setup Checklist');
} else {
// User clicked "No" or X in the title bar.
ui.alert('No tasks were added.');
}
}
function RemoveRoutedOptions() {
var ui = SpreadsheetApp.getUi(); // Same variations.
var result = ui.alert(
'Remove all Routed tasks from the Project Tracker?',
'Are you sure you want to remove all Routed tasks from the Project Tracker?',
ui.ButtonSet.YES_NO);
// Process the user's response.
if (result == ui.Button.YES) {
// User clicked "Yes".
var pglc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Pre-Go Live Checklist');
var vcc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Video Course Checklist');
var rsc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Routed Setup Checklist').hideSheet();
pglc.getRange('E23:E26').clearContent();
vcc.getRange('G10:H15').clearContent();
rsc.hideSheet('Routed Setup Checklist');
} else {
// User clicked "No" or X in the title bar.
ui.alert('No tasks were removed.')
}
}
CodePudding user response:
Sheet.activate() does not accept parameters
rsc.activate('Routed Setup Checklist');
Try changing this:
var rsc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Routed Setup Checklist').activate();
pglc.getRange('B32:B35').copyTo(pglc.getRange('E23:E26'), {contentsOnly:true});
vcc.getRange('B32:C37').copyTo(vcc.getRange('G10:H15'), {contentsOnly:true});
rsc.activate('Routed Setup Checklist');
to this:
var rsc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Routed Setup Checklist');
pglc.getRange('B32:B35').copyTo(pglc.getRange('E23:E26'), {contentsOnly:true});
vcc.getRange('B32:C37').copyTo(vcc.getRange('G10:H15'), {contentsOnly:true});
rsc.activate();