I'm currently working on a project with google-apps-script. My goal is to copy a row multiple times based on the number specified in a certain cell within a spreadsheet. For example, if B2 contains the number 6, I want to duplicate that row 6 times. I've been successful in replicating the row, but I'm encountering issues when trying to manipulate the data further.
Here's the initial data:
Col1 Col2 Col3
Name 6 07/14/2019
This is the desired outcome:
Col1 Col2 Col3
Name Count 1 07/14/2019
Name Count 2 07/14/2019
Name Count 3 07/14/2019
Name Count 4 07/14/2019
Name Count 5 07/14/2019
Name Count 6 07/14/2019
However, this is what I keep getting:
Col1 Col2 Col3
Name Count 6 07/14/2019
Name Count 6 07/14/2019
Name Count 6 07/14/2019
Name Count 6 07/14/2019
Name Count 6 07/14/2019
Name Count 6 07/14/2019
Below is my current code snippet:
function sample(data){
var returnData = [];
var col1 = data[0];
var col2 = data[1];
var col3 = new Date(data[2]);
var count = 0;
if (col2 > 1){
var tempData = [];
for(var i = 0; i < col2; i++){
tempData[0] = col1;
tempData[1] = "Count" + count;
tempData[2] = col3;
returnData.push(tempData);
}
count++;
}
return returnData;
};
I've experimented with moving the count variable around within the code, but I continue to encounter the same issue where only the last count value is being implemented. Can you point out where I may be going wrong?