Currently, I am having an issue with my code that adds responses to a Google Sheets from a Google Forms sheet. The problem is that it always adds the responses to the first column, even if it should go into a different column based on its title. I suspect this is due to the record array simply assigning the response to the first available space, but I don't know how to specify the correct column based on the title. Any help would be greatly appreciated.
function onFormSubmit(event) {
record_array = []
var form = FormApp.openById('12sDsbDUiYvq5Ba2XurnXKh7S5gfM-VDaxzqLG_5n3ao'); // Form ID
var formResponses = form.getResponses();
var formCount = formResponses.length;
var formResponse = formResponses[formCount - 1];
var itemResponses = formResponse.getItemResponses();
for (var j = 0; j < itemResponses.length; j++) {
var itemResponse = itemResponses[j];
var title = itemResponse.getItem().getTitle();
var answer = itemResponse.getResponse();
Logger.log(title);
Logger.log(answer);
record_array.push(answer);
}
AddRecord(record_array[0], record_array[1], record_array[2], record_array[3], record_array[4],
record_array[5], record_array[6], record_array[7], record_array[8]);
}
function AddRecord(q1, q2, q3, q4, q5, q6, q7, q8) {
var url =
'https://docs.google.com/spreadsheets/d/1ZHlvt_Blqe7rDheIxVjvYhneoZfZPGiGbXFSIri6u1c/edit#gid=0';
//URL OF GOOGLE SHEET;
var ss= SpreadsheetApp.openByUrl(url);
var dataSheet = ss.getSheetByName("Sheet7");
dataSheet.appendRow([q1, q2, q3, q4, q5, q6, q7, q8, new Date()]);
}