Hi,
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?
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 .
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.
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?
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;
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.
The === did not help
Nevertheless, I appreciated your willingness to help me!!
So, I have to wait for "a better set of eyes"
Maybe someone from the Retool team.