0

I have a button that works with the function Yeah_Go(), but only when using it on a browser on a laptop. When I try to press the button on an iPad Google Sheets mobile app, it doesn't work. Instead, the drawing is selected and moveable. Not my intention, eh?

Yeah_Go() works properly when you call it directly from the imported macros list, basically, a verify alert Okay_Cancel that leads to another function.

Apparently, button nonfunction is a known challenge on iPads.

It has been suggested to try the onEdit(e) function thus:

function onEdit(e) {
  console.log("Function triggered");
  var sheet = SpreadsheetApp.getActiveSheet();
  var r  = sheet.getRange("J17").getValue();
  if (r == "TRUE") {
    Yeah_Go();
  }
}

When I check the checkbox in J17, nothing happens. Similarly, when I run the macro from the list of imported macros, nothing happens. Not even a happy note in the console...

How can I improve this so it actually works?

1

1 Answer 1

2

Event object fields are text strings, but if you use .getRange().getValue() to get the real value in a cell, the possible values of a checkbox cell with default settings are the Booleans true and false rather than the text strings 'TRUE' and 'FALSE'.

To make your script work, take advantage of the event object, like this:

function onEdit(e) {
  if (e.value === 'TRUE' && e.range.getA1Notation() === 'J17') {
    Yeah_Go();
  }
}
5
  • Thank you for your reply! This absolutely works in Google sheets on a browser. However, Yeah_Go only half works. It won't bring up the alert box on an iPad, even though this system works exactly as you suggest it should on a browser on my desktop. Not sure why. I'd be grateful for suggestions.
    – Chris
    Apr 10 at 0:39
  • function Yeah_Go() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var SORT_FORM = ss.getSheetByName("SORT FORM"); var checkbox1 = SORT_FORM.getRange("H10").getValue(); // Ready to import var checkbox2 = SORT_FORM.getRange("H33").getValue(); // Data Verified
    – Chris
    Apr 10 at 0:41
  • ` if (checkbox1 && checkbox2) { // Both checkboxes are checked, so proceed with function Transfer_Sort_Form_To_DB(); } else { // One or both checkboxes are not checked, display alert message SORT_FORM.getRange('H17').setValue('FALSE'); // Uncheck "Import to DB" var ui = SpreadsheetApp.getUi(); ui.alert('Please check both "Ready to Import" and "Data Verified" first.'); } }`
    – Chris
    Apr 10 at 0:41
  • 1
    Google Apps Script runs on Google's servers rather than your end device. The various UI methods only work with web browser clients. To build a custom user interface that works in the Sheets App in your end device as well, you need to create a Workspace Add-on. There is a learning curve. Please ask only one question per post. Apr 10 at 5:07
  • Thanks @doubleunary, I'll check it out!
    – Chris
    May 27 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.