Here is my third (and hopefully last) question for my current project.
The IF ELSE statement doesn't seem to be working properly in the following code:
function onFormSubmit() {
// onFormSubmit
// get submitted data
var ss =
SpreadsheetApp.openById("1UMSTyjYz2DMubBT54Q7a0V5ie5TAPYFZ2riqV5p93gE");
var sheet = ss.getSheetByName("Submissions");
var row = sheet.getLastRow();
var Col = sheet.getLastColumn();
var headings = sheet.getRange(1,1,1,Col).getValues();
var lastRow = sheet.getRange(row, 1, 1, Col);
var UnitNumber = sheet.getRange(row,3,Col).getValue();
var newSheet = sheet.getRange(row,4,Col).getValue();
// check if username has sheet
if(ss.getSheetByName(UnitNumber)){
var DrillSheet = ss.insertSheet(UnitNumber);
// if not make
} else {
var DrillSheet = SpreadsheetApp.create(UnitNumber);
DrillSheet.getSheetByName('Sheet1').getRange(1,1,1,Col).setValues(headings);
}
// Rename sheet to submission date
DrillSheet.renameActiveSheet(newSheet);
// copy submitted data to Drill sheet
DrillSheet.appendRow(lastRow.getValues()[0]);
DrillSheet.appendRow(['=CONCATENATE(B6," ",B5)']);
DrillSheet.appendRow(['=TRANSPOSE(B1:2)']);
//Hide top rows with raw data
var hiderange = DrillSheet.getRange("A1:A3");
DrillSheet.hideRow(hiderange);
//Widen columns
DrillSheet.setColumnWidth(1,390);
DrillSheet.setColumnWidth(2,700);
}
The goal here is to create a new spreadsheet with the title 'UnitNumber' and sheet title as the submission date IF that spreadsheet doesn't already exist. If the 'UnitNumber' spreadsheet DOES exist, I would like to create a new sheet within that spreadsheet with the title as the submission date.
Currently it is creating a new spreadsheet every time.