Kate Bedrii
Kate Bedrii

Reputation: 103

OnFormSubmit() not firing

I am trying to solve the following case: I have a template that is copied by users and linked to a Google Form. Also, I have a script that does some configuration to the Form Responses tab for its further usage. It works perfectly in the template, however, the installable onFormSubmit() trigger is not copied together with the template. To solve this I added onOpen() trigger that installs the onFormSubmit() which was confirmed to work.

The issue I am facing is that while onFormSubmit() is successfully installed in the template copy, it still does not fire automatically. I assume that this is related to some permissions issue. Is there any way to rewrite the script to avoid additional authorization?

   function onOpen(e) {
 addFormSubmissionListener();
  //// other init...
}

function addFormSubmissionListener() {
  var sheet = SpreadsheetApp.getActive();
  ScriptApp.newTrigger("onFormSubmit")
     .forSpreadsheet(sheet)
     .onFormSubmit()
     .create();
}

function onFormSubmit(e) {
   var range = e.range
   var sheet = range.getSheet();
   var spreadsheet = SpreadsheetApp.getActive();
   if(spreadsheet.getSheetByName('Responses') == null) {
   sheet.setName('Responses');
   sheet.insertColumnsAfter (7,10)
   spreadsheet.getRange('Tech!A:J').copyTo(spreadsheet.getRange('Responses!H:O'), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
  sheet.hideColumns(16, 2)
  var curr_sheet = spreadsheet.getSheetByName('Jira import')
  updateFormulasTwoRows(curr_sheet);
   }
  
}

Upvotes: 0

Views: 258

Answers (1)

Rafa Guillermo
Rafa Guillermo

Reputation: 15375

Answer:

If you create a new project you will always have to authorise it, there isn't really a way of getting around this.

Upvotes: 1

Related Questions