I have encountered an issue with my program where I am able to clear the backlog
status and push changes to the segment = data [x]
array, but I am unable to see those changes in the cell referenced by
var range = sheet.getRange("E2:J10");
. The problem seems to be specifically in the second if statement of the for loop.
// Description:
//The task will be available again after 14 days
//First the program will scan `Task`s to detect backlog tasks
//Then for each task, the program will calculate the difference between the current date `cDate` and the `dateOfTask` = `diff` (inDays)
//If the number of days passed is greater than 14 days, then the task will be set to an empty cell `Task.setblank`
//Once the cell is empty, the task will be available to the algo task manager for prioritization
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = sheet.getRange("E2:J10"); //debugged // test task on line 9
// // Fetch values for each row in the Range.
//const d = dRange.getValues();
var cDate = range.getCell(1,6);
console.log(cDate.getValue());
var data = range.getValues();
console.log(data);
//for loop
for (x=0; x<data.length; x++) {
var segment = data[x];
if (segment[1] == "Backlog"){
var now = new Date();
var dateOfTask = new Date(segment[5]);
var diff = now - dateOfTask;
var timeValue = Math.floor(diff / 1000 / 60 / 60 / 24);
//console.log("Difference in milliseconds: ", diff); // 11140829739
console.log("Difference in days: ", timeValue)
//var timeValue = DAYS(cDate, segment[5]);
if(timeValue > 14){
var refreashBacklog = segment.splice(1,1,"clear contents");
range.setValue(refreashBacklog.segment);
Logger.log(segment);
//ask for help on stackOverflow
}
else{
continue
}
}
else{
continue // remember to set a stop at a certain row so it doesn't go to 999
}
}
}