Input variable not defined in a function

I hope someone can help me.
After a filter block resulting in 14 rows I’m using this code block:

In that block I want to use my function: is_Valid_Alert_Date.
In that function I want to use a field called Notice_date.
But I don’t know the syntax.
Using value.Notice_date is also incorrect and results in ‘value’ is not defined.
Could you help me with this?

kind regards

When you use the data.filter(...) you are basically going to define the condition for each element in the dataset. Something like:

data.filter(x => is_Valid_Alert_Date(x.Notice_date, 30))

The filter function itself needs you to define the conditions so if you defined to the is_Valid_Alert_Date within your code block and it is returning a Boolean value, the above filter should work.

I assumed that Notice_date is a property of the items in your dataset and that the is_Valid_Alert_Date function is defined within the block which checks the Notice_date property and returns true if it is over 30 days ago.

Hi Scott,
Thank you very much for responding and looking at my problem.
The result is not yet what I expected.
That's not because you gave the wrong advice but I think I didn't explain it very well.
Moreover I'm new in Javascript :slightly_frowning_face: .

FilterContracts offers and array of 15 rows.
One of the elements in each row is Notice_date.
I want to reduce the array with the rows where the current date is between Notice_date and 30 days before that Notice_date.
I defined a function called is_Valid_Alert_Date.
I defined that function in the function section:
The function works well when I test it. it returns true or false.
With your suggestion the output is still 15 rows.
I hope this explains a bit better what I'm trying to do.

kind regards from the Netherlands


No problem!

I think the first thing to alter in the code I gave you is to add in the condition you need. Does data.filter(x => is_Valid_Alert_Date(x.Notice_date, 30) == true) provide you with the right set of output rows?

1 Like

Unfortunately not.
Now it returns no rows at all.

Even when I change true to false the number of rows is 0.

Are you able share the is_Valid_Alert_Date code? It could help to verify what the return types are.

This is the code:

var ret = false;
var notice_Date = new Date(
Number(str_Date.substring(6, 10)),
Number(str_Date.substring(3, 5)) - 1,
Number(str_Date.substring(0, 2))
var alert_Date = new Date(notice_Date);
alert_Date.setDate(alert_Date.getDate() - days);
const now = new Date();
if (now >= alert_Date && now < notice_Date) {
ret = true;
return ret;

You can see that the output is a boolean.

Hrm, I would have at least expected the extra == true to return the same number of rows... You might need to use === to make sure the types match in the condition. This may also be irrelevant as the initial code ...filter(x=>is_Valid_Alert_Date(x.Notice_date,30) was returning values.

It seems like the issue would then have to lie in the javascript, but I don't see any obvious reasons there why it would return all of the rows if you have data that should fail the if-statement condition.

Might need a better set of eyes on this one, but I am pretty sure there is a logic issue at play in the script.

Hi Scott,

The === did not help :frowning:
Nevertheless, I appreciated your willingness to help me!!
So, I have to wait for "a better set of eyes" :slight_smile:
Maybe someone from the Retool team.

kind regards

1 Like

I have seen @Tess and @kbn offer great help and direction to those in need. Hopefully this is something simple :slight_smile:

With a little help from my son :slight_smile: we found a solution:

const data =;
const results = [];

for (let i = 0; i < data.length; i++) {
const row = data[i];
const isValid = await is_Valid_Alert_Date(

if ( {

return results;

Maybe there is a better one, but this one works!