I am working on a simple game in google sheets, where a user selects some options and presses a button, then the selections are recorded on a log. I have it working perfectly but only if the log is on a different sheet within the same "workbook". I would really like to have the log be a separate file, but I can not figure out how to get the script to call up this other sheet.
I have tried every code I have found online doing various searches but still can not figure out how to get it to work. As soon as I try to change the destination to an outside sheet I get errors.
Here is what works:
// Function to submit the tempt fate gameplay data to Action Log sheet
function submitDatatemptfate() {
var myGoogleSheet= SpreadsheetApp.getActiveSpreadsheet(); //declare a variable and set with active google sheet
var ActionList= myGoogleSheet.getSheetByName("Action List"); //delcare a variable and set with the User Form worksheet
var ActionLog = myGoogleSheet.getSheetByName("Action Log"); ////delcare a variable and set with the Database worksheet
//to create the instance of the user-interface environment to use the messagebox features
var ui = SpreadsheetApp.getUi();
// Display a dialog box with a title, message, and "Yes" and "No" buttons. The user can also
// close the dialog by clicking the close button in its title bar.
var response = ui.alert("Execute", 'Do you want to execute this action?',ui.ButtonSet.YES_NO);
// Checking the user response and proceed with clearing the form if user selects Yes
if (response == ui.Button.NO)
{return;//exit from this function
}
Here, Action List is the user interface and Action Log is where it is recorded. I want to use this sheet to record the log instead: https://docs.google.com/spreadsheets/d/1fTE_TnuysR5LKbyPDzPxU63hOu6BISH6YYJ0udoViZA/edit#gid=1154300080
I am relatively new to apps script so I feel like the solutions I tried perhaps I am just entering the code incorrectly or don't know which things to change and which not to in order to customize for my own use. For example, here is the latest solution I tried:
// Function to submit the tempt fate gameplay data to Log sheet
function submitDatatemptfate() {
var myGoogleSheet= SpreadsheetApp.getActiveSpreadsheet(); //declare a variable and set with active google sheet
var Game= myGoogleSheet.getSheetByName("Game"); //delcare a variable and set with the Game worksheet
var Log = SpreadsheetApp.openById("1154300080"); ////delcare a variable and set with the Log worksheet
//to create the instance of the user-interface environment to use the messagebox features
var ui = SpreadsheetApp.getUi();
// Display a dialog box with a title, message, and "Yes" and "No" buttons. The user can also
// close the dialog by clicking the close button in its title bar.
var response = ui.alert("Last chance...", 'Are you sure you want to Tempt Fate?',ui.ButtonSet.YES_NO);
// Checking the user response and proceed with clearing the form if user selects Yes
if (response == ui.Button.NO)
{return;//exit from this function
}
...and I get this error:
Exception: Unexpected error while getting the method or property openById on object SpreadsheetApp.
Thank you in advance for any help or advice!