How to get code to run in an order

Hi all! I’m trying to figure out how to get this code to run in order. Apparently when I run this code, everything runs at the same time???

Example:
the field _scanned is initially false

wixData.get(“database”, “_id”)
.then((item) => {
console.log(item._scanned); //we expect this to be false here, but it’s true instead…
if (item._scanned === false ){
console.log(“false”); //this doesn’t even show
console.log(item); //nor this
item._scanned = true ; //but apparently these next 2 codes do run
wixData.update(type, item);
wixLocation.to(“/forum”); //and this one doesn’t…
}
else {
console.log(“true”); //this one does, even though when the page first load the value is false initially
}
})

Thanks in advance!

bump

bump

bump. I’ve just read an article about async and await, but I can’t seem to figure out where to put them so the code runs in a sequence. I really need some advice…

I’m not sure if booleans are set to false by default in the database…they could just be falsy in which case your code would not run as expected. Is your field’s key actually “_scanned” or is it “scanned”? If it’s fetching the wrong field data, it might be throwing back a truthy value. Also have you defined “type” in an upper scope?

Last, make sure you’re declaring what fields to update as per the API: