1

I am trying to filter information on different tables by finding values on them, but when I try to .setValues() nothing happens.

I'm receiving no error in the console.

function GetDrops() {
  // Sheets Variables
  var mobItemDB = SpreadsheetApp.getActiveSpreadsheet()
  var mobDB = mobItemDB.getSheetByName('mobDB')
  var itemDB = mobItemDB.getSheetByName('itemDB')
  var itemDBLastRow = itemDB.getLastRow()
  var itemDBLastColumn = itemDB.getLastColumn()
  var itemArray = itemDB.getRange(8,1,itemDBLastRow-7,itemDBLastColumn).getValues()

  // Drops by Row
  var dropsA1 = mobDB.getRange(3,37,1,26).getValues()
  var dropsB1 = [dropsA1[0][0], dropsA1[0][2], dropsA1[0][4], dropsA1[0][6], dropsA1[0][8], dropsA1[0][10], dropsA1[0][12], dropsA1[0][14], dropsA1[0][16], dropsA1[0][18], dropsA1[0][20], dropsA1[0][22], dropsA1[0][24]]
  
  // Filtered Tabs
  var loot = mobItemDB.getSheetByName('3 Loot')
    var lootLastRow = loot.getLastRow()
  var lootType = 3

  // Find Drops
  var searchV = dropsB1
  var matchRow = itemArray.find(r => r[0] == searchV[0])
  var match = matchRow ? matchRow : ""
  
  // Filter Items
  if(match[3][0] == lootType) {
    loot.getRange(lootLastRow+1,1,1,58).setValues(match)
  }

  // Console
  console.log(match)
}

If I change if(match[3][0] == lootType) to if(match[3] == lootType) I get error The parameters (number[]) don't match the method signature for SpreadsheetApp.Range.setValues.

My debug console shows 'match' with exactly the values that I need to pass to '3 Loot' sheet, but when the script finishes the cells continue to be blank:

Debug Screenshot

TheMaster
  • 45,448
  • 6
  • 62
  • 85
undefined
  • 9
  • 6

1 Answers1

0

As a guess. Try to change:

loot.getRange(lootLastRow+1,1,1,58).setValues(match)

to:

loot.getRange(lootLastRow+1,1,1,58).setValues([match])
Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23
  • Thank you for your answer, I tried and I receive no error but cells are still blank. :( – undefined Aug 12 '22 at 23:24
  • Try to change `if(match[3][0] == lootType)` to `if(match[3] == lootType)` – Yuri Khristich Aug 12 '22 at 23:38
  • 1
    Thank youuuu~! omg, finally worked!!! I knew it had to do something with the 2dimensional array size but I had to also put brackets on match. Thank you very much, now I gotta figure out how to use the .map function to do it with all of the loots on my table... gotta get back to the code. – undefined Aug 12 '22 at 23:42