Reputation: 61
I'm trying to get a script that I've made for a google sheet to trigger when the sheet is opened (since I've found you can't trigger them manually through the mobile app). Somehow, I've managed to get half the script to work, while the other half does not. The script is intended for use on both desktop and mobile, and I want it to clear a predetermined set of cell ranges while also hiding a predetermined set of rows and columns (for formatting purposes). The script runs perfectly on desktop, but the clearRanges portion of the script doesn't run on mobile even though the hideRows/Columns portion of the script does. Any ideas on why this might be? The function I'm using can be seen below:
function onOpen() {
//Create custom menu options
SpreadsheetApp.getUi().createMenu('Invoicing')
.addItem("Clear Data", "clearRange")
.addItem("Submit", "sendEmailWithPdfAttach")
.addToUi()
//Clear ranges
var source = SpreadsheetApp.getActiveSpreadsheet();
source.getRange('A23:A40').clearContent();
source.getRange('H6:I6').clearContent();
source.getRange('H8:I8').clearContent();
source.getRange('F13:F13').setValue('FALSE');
source.getRange('F15:F15').setValue('TRUE');
source.getRange('D19:I19').clearContent();
source.getRange('D23:G23').clearContent();
source.getRange('D31:G31').clearContent();
source.getRange('A42:I44').clearContent();
source.getRange('B24:G25').clearContent();
source.getRange('B28:G29').clearContent();
source.getRange('B32:G33').clearContent();
source.getRange('B35:G40').clearContent();
source.getRange('H24:H29').clearContent();
source.getRange('H32:H33').clearContent();
source.getRange('H35:H39').clearContent();
//Hide rows/columns
var sheets = source.getSheets();
sheets.forEach(function (s, i) {
if (i == sheetNum) {
s.hideRows(45, 400);
s.hideColumns(10, 17);
} else {
s.hideSheet();
}
});
}
The custom menu options are for desktop use and can be ignored. I will also say this is my first time really using Apps Script, and most of this code was taken from elsewhere and modified. If you guys have any clue as to what I can do, I'm all ears. Thanks
Upvotes: 6
Views: 61903
Reputation: 38434
SpreadsheetApp.getUi()
doesn't work on Google Sheets mobile apps (Android and iOS). Unfortunately, the Workspace Add-ons for Google Sheets also don't work on the mobile app.
You might take advantage of onEdit trigger to run a script, i.e., by clicking a checkbox, changing the option selected in a data validation dropdown, or by entering a value in a cell by typing.
Upvotes: 4
Reputation: 3
I use web apps and I insert hyperlinks formulas to execute the scripts. You can add parameters from your sheet in the URL in the formula, eg. Scriptname, sheetId... This has been working well, except sometimes it seems that the scripts are executed multiple times when executed from a mobile phone. This can be fixed by caching specifics of the running script to block the execution if the cache is still in existence
Upvotes: 0
Reputation: 47
There is a simple solution to it, You can create a button on your main spreadsheet and link it with the script!
Open the same sheet on your Mobile Google Chrome
Upvotes: 5