14

I'm developing a interface for a user who uses a google spreadsheet as his database. Nowadays he uses the Google Sheet mobile App (Android and IOs) to update his spreadsheet, and I just can't find any way to create a interface or even call a function on the mobile app. Does anyone knows how can I call a function from the script I've created on the Google Sheets Mobile app? Thanks!

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Felipe Lemos
  • 151
  • 1
  • 1
  • 3
  • 5
    You need to create a stand alone app that will execute from an HTTPS GET or POST request to the Apps Script "exec" url. In the Apps Script code editor, you must deploy the script as a Web App. Either that, or you need to use the Google Sheets API. I don't know anything about Android, so I don't know what you need to do on that end to trigger the process. In any case, you need a way to either make an HTTPS GET or POST request to the stand alone web app, or to the API. – Alan Wells Oct 27 '15 at 17:15
  • https://webapps.stackexchange.com/a/87361/27487 was very helpful for me. – Ryan May 11 '21 at 21:55

2 Answers2

12

The following work with the mobile versions of Google sheets:

  • Custom functions
  • onEdit simple/installed trigger
  • onChange trigger
  • onSelectionEvent trigger(Works partially, if sheets is also open in desktop)

Notes:

  • Avoid calls to get active: getActive() sheet, range or cell. These don't work in mobile or they return a default value like A1 in the first sheet for range.

  • Avoid calls to ui: getUi(). These have no meaning in the context of mobile app and won't work. This includes calls to alerts/prompts. More than likely, You'll hit execution timeout because alerts will wait for user input and this won't show up in mobile. If you do want to show some message, Here is a excellent workaround using images to do the same.

    • Avoid calls to HtmlService. Sidebars/Modal dialogs are not supported in mobile versions.

    • Buttons/Menu items don't work.

  • The best way to support apps script is mobile apps is to chain onEdit calls to a checkbox. Click here for a sample.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • also avoid Browser.msgBox(), it is not supported by the iOS Sheets app, and will break execution without warning. – hymced Oct 21 '22 at 07:20
5

Update Sep-2020

This answer might not be relevant anymore, since Google changed a lot of things in the past year.


You cannot execute Google App Script functions (gas functions) via Google Sheets mobile app.

Alternative #1: (deprecated as of June 2019 - this is no longer possible)

Create Android Add-on

Source: https://developers.google.com/apps-script/add-ons/mobile/

Android add-ons can utilize the Apps Script Execution API to directly call functions in Apps Script projects. This allows Android add-ons to retrieve and manipulate data from a Google Doc or Sheet using standard Apps Script techniques. Just like desktop add-ons, Android add-ons allow you to craft custom user interfaces — but with the full capabilities of the Android platform at your disposal.

Alternative #2

Create a web-app and use Google's Execution API

Source: https://developers.google.com/apps-script/guides/rest/api

The Apps Script Execution API consists of a single scripts resource, which has a single method, run, that makes calls to specific Apps Script functions

Meir Gabay
  • 2,870
  • 1
  • 24
  • 34
  • Using Alternative 2, how is the created App run within Google Sheets? – Rex NFX Jun 11 '20 at 20:56
  • 1
    The web App that I mentioned here is an external application that can manipulate a Google Spreadsheet, without using the UI (API calls). If you want to run a Google Apps Script function in your mobile - you can't. A workaround would be opening the spreadsheet with Chrome Browser and tick the Desktop Site, refresh, and then it'll work. I hate this solution and it's too bad that it's still impossible – Meir Gabay Jun 18 '20 at 17:48