2
votes

I'm trying to create a script that will take a new form response and move it to another sheet based on the information submitted. For example, let's say the form has two answer choices A, B. The spreadsheet has three sheets; Form Responses, Sheet A, Sheet B. If someone submits the form and selects A, I need that new row to be moved from "Form Responses" to "Sheet A." I found someone else's script that does exactly this but using the OnEdit function. I cannot figure out how to modify this script to work when a new form response is submitted.

function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();

if(s.getName() == "Form Responses" && r.getColumn() == 2 && r.getValue() == "A") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Sheet A");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1, numColumns).moveTo(target);
s.deleteRow(row);
  }
}

I used the installable triggers and replaced the OnEdit function with onFormSubmit but that doesn't work. I'd really appreciate it if anyone could help me with this.

Thanks,

3

3 Answers

0
votes

I have a spreadsheet that collects the form submissions and then has extra sheets that have filtered out these submission based on the answers. All this is just with formulas. Could that do the trick also?

0
votes

Try something a little less broad in your comparing of variables,, For instance the sheet that submissions are sent to is a constant and already address.

function formSubmission() {
 var s = SpreadsheetApp.getActiveSheet();
 var data = range.getValues(); // range is a constant that always contains the submitted answers
 var numCol = range.getLastColumn();
 var row = s.getActiveRow;
 var targetinfo = s.getRange(row,(Yourcolumn#here).getValue);
    if(targetinfo() == "Desired Sheet Name") {
      var targetSheet = ss.getSheetByName("Sheet A");
      var targetrow = targetSheet.getLastrow()+1);
      var Targetcol = numCol();
      targetSheet.getRange(targetrow,1,1,Targetcol).setValues(data);
     }
  }

I didn't test that but hopefully it helps look up Event Objects in the developer guide i just recently found it and it clarifies a lot

0
votes

the triggers can be set by going to: enter image description here then set it: enter image description here