unable to access referenced collection

Hi

I have a piece of code on a dynamic page to access a referenced collection, but it’s not working. I can’t figure out why.

Here’s the code:

$w.onReady( () => {

 let itemObj = $w("#dynamicDataset").getCurrentItem();
  wixData.queryReferenced("Kapperszaken", itemObj, "opHours")
    .then( (results) => {
 if(results.items.length > 0) {
 let firstItem = results.items[0]; //see item below
        $w("#text24").text = firstItem;
      } else {
        $w("#text24").text = "nothing found";
      }
    } )
    .catch( (err) => {
 let errorMsg = err;
      $w("#text24").text = "error";
    } );
});

I hope to get an answer soon.

Thanks
Jhon

  1. Try itemObj._id (even though it’s supposed to work your way too).

  2. Make sure the users have permissions for both collections.

  3. You are trying to assign an object to a text element and that’s not supposed to work. Instead do something like:

 $w("#text24").text = firstItem.title;

Hey, sorry for my late answer.

I tried everything you said. didn’t work. It continuously catches an error.

There are a few things that could be the problem but i can’t figure it out.

  • I’m trying to access the referenced collection through a reference field. Not a multi-reference field
  • The items I want to access and display are booleans.

Can you help me further with this information?

Thanks in advance.
Jhon

@jonatandor35 I am a bit further. I managed to succesfully get the first item and display it.
The rest of the collections are booleans. Most of them false. But somehow it dosn’t take thse. If i print the array it says this:

Array(1)

0:  "{\"_id\":\"c639f89b-715d-41be-a4ef-4bf7aef68c96\",\"_owner\":\"e80b8559-8e52-44a1-a9a6-bbb2e15d5e56\",\"_createdDate\":\"2020-09-12T07:52:42.351Z\",\"_updatedDate\":\"2020-09-12T07:52:42.351Z\",\"title\":\"dddd\"}"

The booleans are not in here. How can i get access to these booleans?

This is my total code now:

$w.onReady( () => {

 let itemObj = $w("#dynamicDataset").getCurrentItem();
  wixData.queryReferenced("Kapperszaken", itemObj._id, "opHours")
    .then( (results) => {
 if(results.items.length > 0) {
        console.log(results.items)
 let firstItem = results.items[0]; //see item below
        $w("#text24").text = firstItem.title;
 

 
      } else {
        $w("#text24").text = "nothing found";
      }
    } )
    .catch( (err) => {
 let errorMsg = err;
      $w("#text24").text = "error";
    } );

 
});

Any idea how?

thanks
Jhon

@js4150563 in Wix collections a Boolean field has 3 states:

  1. true

  2. false

  3. not exists (undefined)
    If a cell value is neither true nor false then it just doesn’t exist and you won’t see the field in the query results.
    If you want you can treat the non-exist boolean fields as not true.