One option would be to do the following:
#1. Install onFormSubmit trigger:
Install an onFormSubmit trigger attached to your spreadsheet, so that a function runs every time the form attached to the spreadsheet is submitted (this assumes that your Form is attached to your spreadsheet).
The trigger can be installed either manually, following these steps, or programmatically. To install the trigger programmatically, open a script bound to your spreadsheet by clicking Tools > Script editor, and copy an execute this function once:
function createTrigger() {
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger("submitData")
.forSpreadsheet(ss)
.onFormSubmit()
.create();
}
This will fire a function called submitData every time the form is submitted. Next, then, would be to write function, which should append the submitted data in the format you desire.
#2. Function to append submitted data to sheet:
In order to append the data submitted through the Form on the sheet called Formated responses, you need to use the corresponding event object, which contains the submitted data. You can use this to check how many parts are submitted and the values for its corresponding fields. Then, the method appendRow could be used to append this data to the sheet.
It could be something like this:
function submitData(e) {
var sheet = SpreadsheetApp.getActive().getSheetByName("Formated responses");
var res = e.namedValues;
var numberOfParts = res["Number of parts"][0];
var mainFields = [res["Timestamp"][0], res["Client name"][0], numberOfParts];
switch (numberOfParts) {
case '1':
var fieldsOne = [res["Part identification number"][0], res["Part name"][0]];
sheet.appendRow(mainFields.concat(fieldsOne));
break;
case '2':
var fieldsTwo = [res["#1 part identification number"][0], res["#1 part name"][0]];
sheet.appendRow(mainFields.concat(fieldsTwo));
fieldsTwo = [res["#2nd part identification number"][0], res["#2nd part name"][0]];
sheet.appendRow(mainFields.concat(fieldsTwo));
break;
case '3':
var fieldsThree = [res["#1st part identification number"][0], res["#1st part name"][0]];
sheet.appendRow(mainFields.concat(fieldsThree));
fieldsThree = [res["#2nd part identification number"][1], res["#2nd part name"][1]];
sheet.appendRow(mainFields.concat(fieldsThree));
fieldsThree = [res["#3rd part identification number"][0], res["#3rd part name"][0]];
sheet.appendRow(mainFields.concat(fieldsThree));
break;
}
}
Note:
- The function
submitData could be made simpler (the switch could probably be removed, and a for loop used instead), but the names of the Form fields are not consistent with each other, hindering this option. Because of this, the function has a fair amount of repetition. I'd recommend you to fix the field names and rewrite the function a bit.
Reference:
onFormSubmitthat will take the data fromForm Responsesand copy it to the desired sheet with the desired format, and (3) use sheets formulas to copy the data to the desired format. What do you think would be the most appropriate for your situation? Are you open to using Apps Script? - IamblichusonFormSubmitI mentioned before. In this case, would any of the options I mentioned before would be appropriate for you? - Iamblichus