Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

210
Visualizações
Creating a prompt that opens upon refreshing a Google Sheet

Creating a spreadsheet that will upon either being opened or refreshed should pop up a prompt asking me for the day, store that value in a particular cell and then proceed to ask me a series of other questions.

This is what I have so far:

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)
     }
    }
 }  
}

When I run the script I only get a prompt asking for the day, if I enter Monday this is stored by the other prompt (the question "Did you go to MMA training today") does not run. Additionally, this script does not run upon opening or refreshing my sheet

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Simple triggers have limitations, instead use and installable trigger.

Reference

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

Related

  • Why does ui.alert work but ui.prompt does not with onOpen()?
  • onOpen is not running to other users except to the owner. How to fix this? Google Script GAS
about 4 years ago · Juan Pablo Isaza Relatório

0

There are some things wrong on your code:

1 - On the const day you are using SpreadsheetApp.getUi() but on the const mma you are using ui which is not defined.

2 - You have a function inside an if with function martialArts(), that should be removed.

3 - On the for loop you are selecting the sheet with sheets[i] but then on the if below you select sheets which is all the sheets in the spreadsheet. If you know there is only one sheet or you know which sheets has to be selected you can use sheets[0] or set the if inside the for loop.

With this changes applied your code should look like this:

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda