Hi,
I have two datasets with the same number of items and I’m using a loop to compare two date fields. If both dates are equal or less than today I want to set a field value of the first dataset to false.
It seems to be an issue with the setFieldValue or next() methods, like the loop is continuing before the save is completed or something… I tried many things but I just can’t figure it out.
Any guidance is appreciated! Here’s my code:
export function button1_click(event, $w) {
let today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
const numberOfItems = $w("#dataset1").getTotalCount();
var item_A = $w("#dataset1").getCurrentItem();
var item_B = $w("#dataset2").getCurrentItem();
if((item_A.reviewDate <= today) && (item_B.reviewDate <= today))
{
$w("#dataset1").setFieldValue("study", false);
$w("#dataset1").save();
}
for(var i = 0; i < (numberOfItems - 1); i++)
{
$w("#dataset1").next().then( (_item_A) => {
$w("#dataset2").next().then( (_item_B) => {
if((_item_A.reviewDate <= today) && (_item_B.reviewDate <= today))
{
$w("#dataset1").setFieldValue("study", false);
$w("#dataset1").save();
}
} );
} );
}
}