function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers)
ScriptApp.deleteTrigger(triggers[i]);
ScriptApp.newTrigger("SendGoogleForm")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit().create();
}
function SendGoogleForm(e) {
//Place holders
var name = "";
var nextSheet = "";
//Needed Variables
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("RESPONSE SHEET TITLE");
var sourceRow = sheet.getActiveRange().getRow();
var columns = sheet.getRange(1,1,1,ss.getLastColumn()).getValues()[0];
var range = sheet.getActiveCell();
var startRow = range.getRowIndex();
var numRows = range.getNumRows();
var numCols = range.getNumColumns();
var values = range.getValues();
//Change the Column with Trainee Name Here:
for(var i in columns) {
if (columns[i] == "COLUMN TO ORGANIZE BY") {
name = e.namedValues[columns[i]].toString();
}
}
/*** EXAMPLE ***
case "CANDIDATE NAME":
nextSheet = ss.getSheetByName("TRAINER NAME");
break;
*
***************/
switch(name)
{
default:
nextSheet = ss.getSheetByName("Catch-All");
break;
}
var targetRow = nextSheet.getLastRow() + 1;
if (targetRow > nextSheet.getMaxRows()) nextSheet.insertRowAfter(targetRow - 1);
sheet.getRange(sourceRow, 1, 1, sheet.getLastColumn()).copyTo(nextSheet.getRange(targetRow, 1));
sheet.deleteRow(sourceRow);
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.