Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intialSetup not called #33

Open
ajmas opened this issue Jun 15, 2020 · 0 comments
Open

intialSetup not called #33

ajmas opened this issue Jun 15, 2020 · 0 comments

Comments

@ajmas
Copy link

ajmas commented Jun 15, 2020

When running I found that intialSetup() was not being called, maybe due to a missed step by me? For this reason I removed it and simply assigned the spreadsheet id during the POST call:

function doPost (event) {      
  const lock = LockService.getScriptLock()
  lock.tryLock(10000)

  try {
     // line below changed:
    const doc = SpreadsheetApp.openById(SpreadsheetApp.getActiveSpreadsheet().getId());
    const sheet = doc.getSheetByName(sheetName);

    const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
    const nextRow = sheet.getLastRow() + 1;

    if (event) {
      const newRow = headers.map(function(header) {
        return header === 'timestamp' ? new Date() : event.parameter[header]
      });

      sheet.getRange(nextRow, 1, 1, newRow.length).setValues([newRow])
    }

    return ContentService
      .createTextOutput(JSON.stringify({ 'result': 'success', 'row': nextRow }))
      .setMimeType(ContentService.MimeType.JSON)
  } catch (error) {
    return ContentService
      .createTextOutput(JSON.stringify({ 'result': 'error', 'error': error }))
      .setMimeType(ContentService.MimeType.JSON)
  }
  finally {
    lock.releaseLock()
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant