Al crear una hoja de cálculo que, al abrirla o actualizarla, debería aparecer un mensaje que me pregunte por el día, almacene ese valor en una celda en particular y luego proceda a hacerme una serie de otras preguntas.
Esto es lo que tengo hasta ahora:
function onOpen() { // Prompt for the value const day = SpreadsheetApp.getUi().prompt("Please enter the day.").getResponseText(); //Get all pages in spreadsheet and iterate through const sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets(); for(var i = 0; i < sheets.length; i++ ) { //Set the value in the cell B3 of the page sheets[i].getRange("B2").setValue( day ); } if (day.toLowerCase() === 'monday') { function martialArts() { const mma = ui.alert("Did you go to MMA training today?".ui.ButtonSet.YES_NO); if(mma == ui.Button.YES) { sheets.getRange('C2').setValue(mma) } } } }Cuando ejecuto el script, solo aparece un mensaje que pregunta el día, si ingreso el lunes, esto se almacena en el otro mensaje (la pregunta "¿Fuiste al entrenamiento de MMA hoy?") no se ejecuta. Además, este script no se ejecuta al abrir o actualizar mi hoja
Los disparadores simples tienen limitaciones, en su lugar use un disparador instalable.
Referencia
Relacionado
Hay algunas cosas mal en su código:
1 - En el const day , está utilizando SpreadsheetApp.getUi() pero en el const mma , está utilizando una interfaz de ui que no está definida.
2 - Tiene una función dentro de un if con function martialArts() , que debería eliminarse.
3 - En el ciclo for , está seleccionando la hoja con sheets[i] pero luego en el if debajo, selecciona sheets que son todas las hojas en la hoja de cálculo. Si sabe que solo hay una hoja o sabe qué hojas deben seleccionarse, puede usar sheets[0] o establecer el if dentro del bucle for .
Con estos cambios aplicados, su código debería verse así:
function onOpen() { // Prompt for the value var ui = SpreadsheetApp.getUi(); const day = ui.prompt("Please enter the day.").getResponseText(); //Get all pages in spreadsheet and iterate through const sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets(); sheets[0].getRange("B2").setValue(day); if (day.toLowerCase() === 'monday') { const mma = ui.alert('Did you go to MMA training today?', ui.ButtonSet.YES_NO); if (mma == ui.Button.YES) { sheets[0].getRange('C2').setValue(mma) } } }