Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Google Apps Scripts to Run on Mobile

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

like image 534
Zach S Avatar asked Jan 02 '23 06:01

Zach S


1 Answers

  • 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

  • On the extreme Right Top corner, click on the three dots. A drop-down menu Opens
  • Select "View in Desktop Mode".
  • Notice, the button your Spreadsheet is now clickable, as the sheet interprets the user to be logged on to a PC
  • Now, Just Click on the button and let the script do its magic
like image 110
Anshul Bansal Avatar answered Jan 08 '23 07:01

Anshul Bansal