12

I have created an image button in Google spreadsheet and have assigned function, to perform some action. But this button click is only working on windows and not working on Android mobile sheet or mobile browser. what is a workaround for this issue?

TheMaster
  • 45,448
  • 6
  • 62
  • 85
PK Inception
  • 141
  • 1
  • 1
  • 4
  • Please check [this](https://webapps.stackexchange.com/questions/87346/add-a-script-trigger-to-google-sheet-that-will-work-in-android-mobile-app). I guess it solves the problem. – Péter Baráth Oct 08 '19 at 13:34

2 Answers2

16

Workaround is to use checkboxes(say, in F1) instead of buttons/Images. Then hook your function, that is supposed to run on button click to a trigger function like onEdit().

Sample script:

function onEdit(e){
  const rg = e.range;
  if(rg.getA1Notation() === "F1" && rg.isChecked() && rg.getSheet().getName() === "Sheet1"){
    callFunctionAttachedToImage();
    rg.uncheck();
  }
}

Some limitations of this workaround in mobile app is described here.

References:

TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • 1
    how do I link my script to checkbox. likewise there is an assign script option is available for button, no such option avail for checkbox. – PK Inception Sep 09 '19 at 18:04
  • @PKI You don't assign it. You use the onEdit trigger like I've shown above. onEdit, if the edit is in F1, `callFunctionAttachedToImage` is called. – TheMaster Sep 09 '19 at 18:43
  • Excellent! Thanks for this @TheMaster. It worked for me. Crazy that Google doesn't give a way to run Apps Script stuff via a mobile menu. However, I guess there are other issues - as I found that if I put an Alert function in the code above, it would hang and the alert won't show on Mobile! So no interaction or it'll hang and timeout - check exec logs to see. – kgingeri Jan 22 '21 at 22:22
  • 1
    @kgingeri [I am aware of the issue](https://stackoverflow.com/a/47207643/) – TheMaster Jan 23 '21 at 04:58
0

Here is the script which works on mobile too when I put checkbox on Row 39 - Column 6

function onEdit(e) {

  var ss = SpreadsheetApp.getActiveSheet();
  var r = ss.getActiveCell();

  //1.Change 'Sheet name Here' to be matching your sheet name
  
  if (r.getRow()== 39 && r.getColumn()== 6 && ss.getName()=='Sheet name Here') {

      // 2. If Edit is done in cell F39  And sheet name is 'Sheet name Here' then:
      ss.getRange('G40:G45').clearContent()
  }
};
Lee Taylor
  • 7,761
  • 16
  • 33
  • 49