4

I use a script in my SpreadSheet to add row below the active one and copy there content from active row. On PC I can trigger the script via image/drawing and it works nicely. But I cannot figure out how to make it work in iOS app where trigger from image doesn't work and where copying content from one to another is nightmare. I tried onEdit and isChecked for each line but it would give me new row on every edit. Could you help, please?

function addRow() {
var sheet = SpreadsheetApp.getActiveSheet(),
    row = sheet.getActiveCell()
        .getRow(),
    rangeToCopy = sheet.getRange(row, 1, 1, 20);
sheet.insertRowAfter(row);
rangeToCopy.copyTo(sheet.getRange(row + 1, 1));
}

https://docs.google.com/spreadsheets/d/12WErwXRn6yPvG8FuR-DwltaSC-Fuk7aTB2NrJWMKFQ4/edit?usp=sharing

Rubén
  • 34,714
  • 9
  • 70
  • 166
sidlo
  • 183
  • 1
  • 10
  • 2
    Does this answer your question? [Executing Google Apps Script Functions from Mobile App](https://stackoverflow.com/questions/33373826/executing-google-apps-script-functions-from-mobile-app) – Rubén Jun 25 '20 at 18:53

2 Answers2

4

Check-boxes will work great on the iOS interface, I have actually used this for a major restaurant with high-volume delivery orders (checking off "ready" orders and auto-texting drivers that their order is ready). The only change we need to make to your spreadsheet is to add a checkbox for each individual row. enter image description here

The trick is to use an onEdit trigger, by renaming your function "onEdit"

Here is the script:

 function onEdit(e) {
      //IF the cell that was edited was in column 1 and therefore a checkbox AND if the cell edited was checked (not unchecked):
      if (e.range.columnStart === 1 && e.range.getValue() === true) {
        var sheet = SpreadsheetApp.getActiveSheet(),
            row = sheet.getActiveCell()
            .getRow(),
            rangeToCopy = sheet.getRange(row, 1, 1, 20);
        sheet.insertRowAfter(row);
        rangeToCopy.copyTo(sheet.getRange(row + 1, 1));
        //Reset checked boxes
        sheet.getRange(row,1,2,1).setValue(false);
      }
    }

NOTE: if you check a bunch of boxes quickly in succession, google scripts might miss some. This is fine because, they will stay checked and you will be able to see the ones that didn't run. Simply un-check and check them again to run the script as normal.

Jeremy Irons
  • 472
  • 5
  • 15
  • 1
    This is brilliant. It works like a charm even on iOS. Love it. Thank you so much for thorough explanation! – sidlo Jun 25 '20 at 20:13
2

You could run your function with something like this:

function onEdit(e) {
  const sh=e.range.getSheet();
  if(sh.getName()=='Your sheet name' && e.range.columnStart=='column you choose' && e.value=='TRUE') {
    e.range.setValue('FALSE');//resets the checkbox
    const row=e.range.rowStart;
    yourfunction(row);
  }
}

I would use one column of checkboxes and which ever one you check it will run your function and pass the active row to it. Or you could pass e to it and get active row with e.range.rowStart.

Cooper
  • 59,616
  • 6
  • 23
  • 54