Reputation: 19
I am getting the following error for the last line of my Apps Script code - “ Exception: The parameters (number[]) don't match the method signature for SpreadsheetApp.Range.setValues. (line 52, file "TaskCompletionDate")”
The code picks up the spreadsheet range using sheet.getDataRange() and based on certain conditions, picks values from this range to a column array called Col8. After the array Col8 is completely written, I paste this Col8 into my spreadsheet. The error refers to this step.
Shortened version of my code is as follows:
var spreadsheet = SpreadsheetApp.openById("Spreadsheet_ID");
var sheet = spreadsheet.getSheetByName("Sheet_name");
var rows = sheet.getLastRow();
var range = sheet.getDataRange();
var values = range.getValues();
var today = new Date();
var yesterday = new Date();
yesterday.setDate(today.getDate()-1);
var Col8 = new Array(rows-1,1);
for (var i=2; i<=rows; i++)
{
if (values[i-1][1] == "Completed")
{
if (!values[i-1][8])
Col8[i-1][1].setValue(values[i-1][1]);
}
}
sheet.getRange(2,8,rows-1,1).setValues(Col8);
Spreadsheet columns can be seen here
What am I missing? I am not a programmer, nor do I know JavaScript or Apps Script, but have been building small Apps Script snippets using the App Script documentation and other app script resources on the net.
Upvotes: 0
Views: 12962
Reputation: 64032
This is the basic starting point. But I need information from your spreadsheet image in order to make sure the indices are correct. I noticed that you create today and yesterday but you don't actually use them.
function myfunvtion() {
var ss=SpreadsheetApp.openById("Spreadsheet_ID");
var sh=ss.getSheetByName("Sheet_name");
var rg=sh.getRange(2,1,sh.getLastRow()-1,sh.getLastColumn());
var vs=rg.getValues();
var today=new Date();
var yesterday=new Date(today.getFullYear(),today.getMonth(),today.getDate()-1);
var oA=[];
for (var i=0; i<vs.length;; i++) {
if (values[i][1]=="Completed" && !values[i][18]) {
oA.push([vs[i][1]]);//it looks like your fixing something in your spreads
}
}
sh.getRange(2,8,oA.length,1).setValues(oA);
}
Upvotes: 1