I'm new to stackover flow and coding in general. I've put together a script that pulls information from array that pulls the information from the main sheet. The scripts pulls the type of sheet to pull from templates and fills it out based on the array data. It works fine with the first row of data but my variables don't update after an increment command so it gets stuck on the first entry. Apologies if I'm explaining it poorly. Function: 1.Pulls room type based on row 4 of Arraydata 2.Renames it based on row 4 of array data 3.Fills in Data from row 4 of Array data 4.Increments variable of row so that this can run the script again on row 5 until there is no more array data.
I have replaced the actual sheet ID for security
function createautomation() {
do{
var roomlist = SpreadsheetApp.getActiveSheet().getRange("Room List!A1:G100").getValues();
var i = 4
var ss = SpreadsheetApp.getActiveSpreadsheet();
var commissioning_template = SpreadsheetApp.openById('ID')
var roomtype = roomlist[i][5]
var copyroom = (`Copy of ${roomtype}`)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var first = ss.getSheetByName(copyroom);
var roomname = roomlist[i][1]
var tab = (`${roomname} - ${roomtype}`)
var second = ss.getSheetByName(tab)
var room1 = (`${tab}!B1`)
var roomnum = (`${tab}!B2`)
var floor = (`${tab}!D2`)
var address = (`${tab}!B3`)
var siteName = (`${tab}!D3`)
var siteCode = (`${tab}!E3`)
var sourcenum = roomlist[i][0]
var sourceflr = roomlist [i][4];
//Copy The spreadsheet
commissioning_template.getSheetByName(roomtype).copyTo(ss);
//Rename Sheet
ss.getSheetByName(copyroom).setName(tab);
//Set Room Name
ss.getRange(room1).setValue(roomname);
//Set Room Number
ss.getRange(roomnum).setValue(sourcenum);
//Set Floor
ss.getRange(floor).setValue(sourceflr);
//Set Address
ss.getRange(address).setValue(roomlist[1][2]);
//Set Site Name
ss.getRange(siteName).setValue(roomlist[0][2]);
//Set Site Code
ss.getRange(siteCode).setValue(roomlist[2][2])
//increment the value of i
i++;
console.log(i)}
while(roomname !="")
}