I have two databases A + B and the function of the code is that it compares the values in database A and finds them, but the condition in the code is that it does not save in database B in case the number matches the numbers in database A, my problem is that the code finds the matching value And it saves and I want to save only in case the values do not match… Is there a solution?
Note: The code works correctly only with the first value in database A (number database)
this is My Code 👇🏻
$w.onReady(() => { ///--------------------------------------------------
$w("#dataset1").onReady(async () => {
let length = await $w('#dataset1').getTotalCount();
console.log("Data-Length: ", length)
$w('#button83').onClick(async () => {
console.log("Click")
let code = await ($w('#input24').value).toString();
console.log("Input-Code: ", code)
let data = await ($w("#dataset1").getItems(0, length));
console.log("Data: ", data)
for (var i = 0; i < length; i++) {
let dataCode = String(data.items[i].Numbers);
console.log("CODE: ", dataCode)
if (dataCode === code) {
console.log("CODE found!")
$w('#button82').expand();
$w('#button83').collapse();
$w('#text168').text = "The membership number is correct, please press subscribe"
//$w('#text170').show();
$w('#box2').hide();
break;
} else {
let toInsert = {
"name": $w('#input23').value,
"email": $w('#input21').value,
};
wixData.insert("WrongReg", toInsert)
.then(() => {
console.log("New User-Data saved.")
// here your CODE to disable BUTTON after the user was added to the DATABASE.
$w('#button82').disable();
$w('#button83').disable();
$w('#box2').show();
$w('#button82').collapse();
$w('#text168').show();
$w('#text168').text = "The membership number is incorrect"
$w('#button83').expand();
})
.catch((err) => { let errorMsg = err;
console.log(errorMsg); });
}
}
});
});
});
export function button84_click() {
$w('#box2').collapse()
}
any help