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

204
Views
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 answers
Answer question

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 Report

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 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!