How do write script for below
google form response as below
| time stamp | Document No. | Recipient Name | Document transmittal ref no |
|---|---|---|---|
| 7/9/2021 21:36:11 | 170709, 170738, 171769, 172003, 172025 | Susan | 20210001 |
| 7/18/2021 18:19:59 | 131034, 131192, 132438, 132465, 133016 | Jhon | 20210002 |
i want processed data look like below
| Time stamp | Document no. | Recipient Name | Document transmittal Ref no. |
|---|---|---|---|
| 7/9/2021 21:36:11 | 170709 | Susan | 20210001 |
| 7/9/2021 21:36:11 | 170738 | Susan | 20210001 |
| 7/9/2021 21:36:11 | 171769 | Susan | 20210001 |
| 7/9/2021 21:36:11 | 172003 | Susan | 20210001 |
| 7/9/2021 21:36:11 | 172025 | Susan | 20210001 |
| 7/18/2021 18:19:59 | 131034 | Jhon | 20210002 |
| 7/18/2021 18:19:59 | 131192 | Jhon | 20210002 |
| 7/18/2021 18:19:59 | 132438 | Jhon | 20210002 |
| 7/18/2021 18:19:59 | 132465 | Jhon | 20210002 |
| 7/18/2021 18:19:59 | 133016 | Jhon | 20210002 |
the current script was done below
function formatData() { // File var ss = SpreadsheetApp.getActiveSpreadsheet(); // Get responseData sheet var rawData = ss.getSheetByName('documentTransmittal'); // Input data var data = rawData.getRange("A2:D").getValues(); // Gets titles and options in a single call to the sheet // Initialise an array that will hold the output var outputArray = []; // Name a variable to hold the data from each set of options var options; // Start looping through the data for (var row = 0; row < data.length; row++) { // Split the document with individual no. options = data[row][1].split(", "); // Loop through the array of split options and place each of them in a new row for (var element = 0; element < options.length; element++) { outputArray.push([data[row][0], // Place the title in a new row options[element]]); // Place one option in the 2nd column of the row } // Options loop ends here } // Data loop ends here // Get processedData sheet var processedData = ss.getSheetByName('responseData'); // Get last row in processedData sheet var lastRow = processedData.getLastRow(); // Post the outputArray to the sheet in a single call processedData.getRange(lastRow + 1, 1, outputArray.length, outputArray[2].length).setValues(outputArray);}above only can help get 2 row data only