Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
Creación de un aviso que se abre al actualizar una hoja de cálculo de Google

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

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Los disparadores simples tienen limitaciones, en su lugar use un disparador instalable.

Referencia

  • https://developers.google.com/apps-script/guides/triggers
  • https://developers.google.com/apps-script/guides/triggers/installable

Relacionado

  • ¿Por qué funciona ui.alert pero ui.prompt no con onOpen()?
  • onOpen no se ejecuta para otros usuarios excepto para el propietario. ¿Cómo arreglar esto? GAS de secuencia de comandos de Google
about 4 years ago · Juan Pablo Isaza Report

0

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) } } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!