So I am kind of new to Google Scripts, and am not sure what exactly I am doing wrong. I am trying to copy the results from a dialog box to a cell in google sheets. However, the current method I am trying is not working, and I get a response saying "Cannot Find Function to CopyTo in Object (Response)"
function Cancel() {
var ui = SpreadsheetApp.getUi();
var result = ui.prompt(
'What day did you cancel?',
'Please enter the date as mm/dd/yyy',
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
var text = result.getResponseText();
var sheet = SpreadsheetApp.getActiveSheet(),
row = sheet.getLastRow();
if (button == ui.Button.OK) {
// User clicked "OK".
sheet.insertRowAfter(row);
text.copyTo(sheet.getRange(row + 1, 1));
ui.alert('The Date has Been Recorded');
} else if (button == ui.Button.CANCEL) {
// User clicked "Cancel".
ui.alert('I did not get your name.');
} else if (button == ui.Button.CLOSE) {
// User clicked X in the title bar.
ui.alert('You closed the dialog.');
}
}
Could anyone take a look at my code and make suggestions on how I can go about copying the response to a cell. Any help would be greatly appreciated.
How about:
instead of: text.copyTo(sheet.getRange(row + 1, 1));
try: sheet.getRange(row + 1, 1).setValue(text);