Learn-to-send-email-via-google-script-html-no-server: Create multiple new rows in google sheet with one form submit

Created on 16 Aug 2018  路  2Comments  路  Source: dwyl/learn-to-send-email-via-google-script-html-no-server

Hi, everyone. I am hoping to use this to basically emulate a physical form that we use at work now. I would love to be able to add several rows at a time on a form submit. Is this something that I can do now with the project as it is written? If so, can someone direct me to that information? Otherwise, any suggestions for how to make this happen? I am finding the google sheets documentation a little cryptic.

Thanks!

help wanted question technical

Most helpful comment

This is great! Thank you so much.

All 2 comments

function test() {
  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.appendRow(['one cel', 'second cel', 'etc']);
}

appendRow also has another interesting characteristic, it's concurrent-safe. Which means it can be triggered multiple times in parallel and won't mess up. If you want to implement your own function concurrent safe you have to lock it, like this:

function insertRow(sheet, rowData, optIndex) {
  var lock = LockService.getScriptLock();
  lock.waitLock(30000);
  try { 
    var index = optIndex || 1;
    sheet.insertRowBefore(index).getRange(index, 1, 1, rowData.length).setValues([rowData]);
    SpreadsheetApp.flush();
  } finally {
    lock.releaseLock();
  }
}

don't forget to retrieve your POST or GET datas with doPost() or doGet() native functions

This is great! Thank you so much.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

austinjupiter picture austinjupiter  路  3Comments

ThomasSalty picture ThomasSalty  路  4Comments

Brothman picture Brothman  路  3Comments

tiffting picture tiffting  路  4Comments

onurusluca picture onurusluca  路  4Comments