Logic for Condition in Appscript

16 views Asked by At

logic needs to be updated to work for changing years. If the last two quarters are Q3 and Q4 (as they are now), the year we should be looking for is last year. If the last two quarters are Q4 and Q1, we need to be looking for Q4 of last year and Q1 of the current year. If the last two quarters are Q1 and Q2 or are Q2 and Q3, then we're looking at quarters in the current year.

This is what I've Rn:

        for (var i = 0; i < lastColumn; i++) {
          var headerValue = sourceSheet.getRange(2, i + 1).getValue();


          if (headerValue instanceof Date) {
            var headerMonth = headerValue.getMonth() + 1; // Adding 1 to match month indices in Date object
            var headerYear = headerValue.getFullYear();
            var headerQuarter = getCurrentQuarter(headerMonth);


            if (lastTwoQuarters.includes(headerQuarter) && headerYear === currentYear) {
              dataToPaste.push(rowDataToCopy[i]);
            }
          }
        }
0

There are 0 answers