I have this Google Apps Script to read rows from a Google Spreadsheet but I need to find out the row number of the active array element.
The goal is to check if a row has been processed or not (statusverwerkt
variable). If the value of statusverwerkt
is x
I create a Google event in the calendar and I want to change to value of statusverwerkt
to yes
There might be another way to do this, but it would be helpful to find out the current row in the array element.
This is my code:
function caltest1() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = SpreadsheetApp.getActiveSheet().getLastRow();
var Totalrows = sheet.getDataRange();
var TotalNumrows = Totalrows.getNumRows();
var Reservations = range-1;
var startRow = 2; // First row of data to process
var numRows = Reservations; // Number of rows to process
var dataRange = sheet.getRange(startRow, 1, numRows, 17);
var data = dataRange.getValues();
var cal = CalendarApp.getDefaultCalendar();
for (i in data) {
var row = data[i];
var title = row[2]; // First column
var desc = row[7]; // Second column
var tstart = row[9];
var tstop = row[10];
var loc = row[3];
var statusverwerkt = row[14];
if (statusverwerkt = "x"){
cal.createEvent(title, new Date(tstart), new Date(tstop), {description:desc,location:loc});
//set statusverwerkt value = "yes"
}
else {
// statusverwerkt = "x"
}
}