So I am currently in the process of generating ticket numbers based on uniqueIDs. For each person have some data, the most important of which is [uniqueID, ticketNumber (currently emplty), numberOfEntries,...]. What I want to generate is a list where if someone has 3 entries, they would have three rows, where the only difference is the ticket number. I would like the ticket number to be of the form UniqueID-1, UniqueID-2, UniqueID-3 etc.
So far I have this:
function autoDup() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var data = sheet.getDataRange().getValues();
var newData = [];
var temp = [];
for(var n in data){
var unID = data[n][0]; //get uniqueID from column 1
if(!Number(data[n][2])){continue};// if column 3 is not a number then do nothing
for(var c=0 ; c < Number(data[n][2]) ; c++){ //loop through the entries
temp[c] = data[n];
temp[c][1] = String(unID) + "-" + String(c+1);
Logger.log(temp[c]);
newData.push(temp[c]);//store values
Logger.log(newData);
}
}
sheet.getRange(1,1,newData.length,newData[0].length).setValues(newData);// write new data to sheet, overwriting old data
}
In the execution log, I get that temp[c]
produces the data that I want, however newData.push(temp[c])
ends up overriding the previous pushes and I get the same ticket number duplicated for a particular entry. This is not what I expected, and I don't understand where I am going wrong?
Please let me know if I haven't explained something well, and I will clarify any points.