0

My first time here, so apologies for any mistakes I may do in my post. I'm currently building my first script and I have come to a blocking point (in the last step of the process) that I can't solve.

The issue is produced in an 'if' condition used for copying the values only when two conditions are met. One condition is met and working properly but the second is not working (I have tested both separately). This second condition is a date and in the code I have written it as follows:

 if ((items[z][2] == aux) && (items[z][1] ==  datefilter))

with items being a 2D array with the following structure:

and datefilter being a variable obtained from a dropdown selection ("Data Validation" functionality) that uses the range B2:B of the image above as a source but in another sheet:

var datefilter = outsheet.getRange('C2').getValue();

When checking the logs of both variables with the following code:

      Logger.log(datefilter)
      Logger.log(typeof datefilter)

      var valores1 = items[z][1];
      Logger.log(valores1)
      Logger.log(typeof valores1)

I get that the two variables are objets and have the same value:

8:02:42 PM  Info    Sun Dec 26 18:00:00 GMT-05:00 2021
8:02:42 PM  Info    object
8:02:42 PM  Info    Sun Dec 26 18:00:00 GMT-05:00 2021
8:02:42 PM  Info    object

Additional info (I don't know if it is relevant): Note that in the image attached, the range gets the information from a query and therefore I get a text instead of a date for column B(i.e instead of 12/20/2021 I get 44550). As a reminder, this column serves as the input for datefilter as well as for the array position.

Does anyone have a solution so my filter works? Many thanks in advance.

  • I didn't see an image, but it always helps to share a link to a sample sheet. Also, it might help if you reduced the detail of your post regarding stuff that's working. It's good that you've identified that only one of your conditions is faulty, no need to add detail on successful code. – pgSystemTester Dec 28 '21 at 19:45
  • Also, I presume you know that google sheet arrays are base zero? Perhaps one condition needs to be `item[z][0]` instead of `item[z][2]`? – pgSystemTester Dec 28 '21 at 19:48
  • Use [tables](https://webapps.stackexchange.com/a/161855/) to show your data structure. If you share spreadsheets, do note that [your email address can be accessed by the public](https://meta.stackoverflow.com/questions/394304/). – TheMaster Dec 28 '21 at 20:00
  • Try .getRange('C2').getDisplayValue(). – liquidkat Dec 28 '21 at 20:01
  • You can't compare dates like that. See https://stackoverflow.com/questions/492994/compare-two-dates-with-javascript – TheMaster Dec 28 '21 at 20:03

0 Answers0