Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9788

Need help with Google Sheets moving rows and setting formatting upon move completion for Google Sheets Script

$
0
0

I have a script which I use to copy rows with checked checkboxes to a "Copmpleted sheet". The script is set to run on a timer and it works without any issues. The script and description can be seen here;

Need help with Google moving rows on open for Google Sheets Script

I have since added another script (a modified version of the script above) to copy daily tasks from Task sheet to ToDo list. Almost everything is working without issues. The problem is that the copied data looses checkbox formatting. I have tried to solve the issue but was not able to. Only a part of "pushed" over data has checkboxes set. If I run the script it will copy over the data but will not set the checkboxes. If I run the script again it will set the checkboxes on data copied over earlier but not the currently copied data. I am guessing the issue is either with "datarange" or loop script ending too soon but I just cannot figure it out. The script is below.

Row 1 has a header in it.

I would also like to add a condition saying (see below) but I am not sure of syntax or where to put it

if ( values[i][0] !== "") AND ( values[i][1] == 1st of the month ) copy this row

else if

( values[i][0] !== "") copy this row

Trying to set up copying of daily task every day and only once a month tasks only once on the 1st of each month.

function CopyTasks() {var ss = SpreadsheetApp.getActiveSpreadsheet();  var sheet = ss.getSheetByName("ToDoRepeatTasks");  var targetSheet = ss.getSheetByName("ToDo");   // get the last row and column of data on "ToDoRepeatTasks" and "ToDo"  var sheetLR = sheet.getLastRow();  var sheetLC = sheet.getLastColumn();    var targetLR = targetSheet.getLastRow();  var ToDoLC = targetSheet.getLastColumn();  var ToDoLR = targetSheet.getLastRow();  // assume that there are headers in row 1  var range = sheet.getRange(2,1,sheetLR-2+1,sheetLC);  // Logger.log("DEBUG: the range is "+range.getA1Notation());  // get the values    var values = range.getValues();  // create a temporary array to hold the "moved" rows  var temp = []  for (var i=0;i<sheetLR-2+1;i++){    var thisrow = i+2;    if ( values[i][0] !== ""){      // temporary array for this row      var thisrow = [];      //Logger.log("DEBUG: do something")      for (var c = 0; c<sheetLC; c++){      thisrow.push(values[i][c]);      }      // add this row to the temporary array      temp.push(thisrow);        }else    {      //Logger.log("do nothing")    } }  // update the rows to the targhet sheet  var targetrange=targetSheet.getRange(targetLR + 1, 1,temp.length,sheetLC);  targetrange.setValues(temp);   // modification ------------------------------------------------------------------var checkboxRange = targetSheet.getRange(2, 2, ToDoLR-1+1, 1);  // Logger.log("DEBUG: checkbox range = "+checkboxRange.getA1Notation())  var checkboxValues = checkboxRange.getValues();  // Logger.log(checkboxValues); // DEBUG  // change from the bottom up so that row numbers retain content  for (var r=ToDoLR-1;r>=0;r--){    // Logger.log("DEBUG: r = "+r+", row = "+(r+2)+", checkbox value  = "+checkboxValues[r]);    if (checkboxValues[r] == "false"){      // Logger.log("DEBUG: set checkboxes")      checkboxRange.insertCheckboxes();    }   else   {     // Logger.log("DEBUG: don't do anything")   } }  }

Viewing all articles
Browse latest Browse all 9788

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>