.getCurrentItem Always Returns False in Boolean Fields [Database/Dataset]

Hello there,

I was trying to retrieve a Boolean value from my database, which I’m sure it’s true, but the the code that depends on its value doesn’t work, and when logging the result the the console it returns false .

let item = $w('#dataset1').getCurrentItem();
let appealed = item.rejected // which is a Boolean value [true]

if (appealed === true) {
    $w('#appeal').disable().then(() => {  // the code doesn't run here
        $w('#appeal').label = "Appealed";
    })
} else {
console.log("User hasn't appealed yet") // but runs here
}

While the value in the database is true, I got false whenever I log the value to the console. And I get the message: “User hasn’t appealed yet”.

Why is this happening!!

Any help will be appreciated.

Hi Ahmad,

You need to make sure that the page and dataset are loaded before this code executes:

$w.onReady(function () {
    $w('#dataset1').onReady(() => {
        let item = $w('#dataset1').getCurrentItem();
        let appealed = item.rejected 
        if (appealed === true) {
            $w('#appeal').disable().then(() => {  
            $w('#appeal').label = "Appealed";
            })
        } else {
            console.log("User hasn't appealed yet") 
        }
    })
});

Hi Anthony - @tony-brunsman .

This is function that’s been called in the onReady function, I have other if statements inside the same function that depends on getting the current item from the dataset , and they’re working flawlessly.

Here is the complete image:

 $w.onReady( async function () {
  checkIfAppealed();
 })
 
 function checkIfAppealed() {
  let item = $w('#returnItemDataset').getCurrentItem();
  
  let requestStatus = item.requestStatus;
  let appealed = item.appealed;
  
  if ((requestStatus === "Rejected") || (requestStatus === "Completed" && appealed === false)) {
    $w('#appealBox').expand().then(() => {
      if (appealed === true) { // should be true
        $w('#appeal').disable().then(() => {
          $w('#appeal').label = "Appealed";
         })
      } else {
        console.log("User hasn't appealed yet")
     }
   })
 }  
}

I have only one entry in the database which I checked its appealed field box to be true by myself, so the code should return true, but instead it returns false, I used a console.log to check the “appealed” value in the onReady function and it also printed false.

Any ideas?

It worked without me doing anything :joy:

These bugs must be fixed.

Depending on server response, it is going to sometimes behave the way you originally reported until you put the database onReady on it like follows:

$w.onReady( async function () {
  $w('#dataset1').onReady(() => {
      checkIfAppealed();
   })
 });  

Hi @tony-brunsman ,

This is an example code, the original code has the onReady as an async function, and the code runs inside the repeater .onItemReady function, so it’s not an excuse for the code to return the wrong answer.

Also, if it was a synchronization issue, the code must return undefined, not false, right?

@ahmadnasriya I just wanted to be sure that you were taking these things into account.

You raise a good question, but I’m wondering if you have stepped through the code to see if you could gain some insight into why it’s evaluating the way it is. Way more often than not, what we think are bugs end up being something amiss in our code when we dig into it further.

@tony-brunsman - I think I know what the problem is, when you make some changes on a particular page, especially the code, and then hit the preview page, the preview content is actually the content cached on the browser, and the changes doesn’t take effect on the preview immediately.

To see the latest update when previewing the site, while you’re previewing, go to any page, and then go back to the page that you’re editing, the latest changes will appear.

Another thing that I noticed, with Boolean fields, when adding an entry to the database, the Boolean value is not checked, and thus should be false, I mean looking at the database, the checked fields makes an impression that the field is true, and the empty (unchecked) field give an impression that the field value is false, but they’re not, their value is undefined.

And that make sense, since there’s a lot of cases that you want to check whether the field has been modified or not, if it hasn’t, the value should be undefined, and after the field is modified, only returns true or false.

I know that you’re aware of that since you’re one of Corvid masters, but others visiting this thread might benefit from it, also it’s a chance for me to make sure if my observations were true or false.