# Using Code to Filter Dataset Not Working

**URL:** <https://forum.wixstudio.com/t/using-code-to-filter-dataset-not-working/3887>\
**Category:** Ask the community\
**Tags:** wix-bookings, wix-members-area, question, code\
**Created:** [March 7, 2023, 10:12am UTC](https://forum.wixstudio.com/t/using-code-to-filter-dataset-not-working/3887 "2023-03-07T10:12:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miran-stubican](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/miran-stubican/32/36638_2.png) [@miran-stubican](https://forum.wixstudio.com/u/miran-stubican)\
**Post date:** [March 7, 2023, 10:12am UTC](https://forum.wixstudio.com/t/using-code-to-filter-dataset-not-working/3887/1 "2023-03-07T10:12:07Z")

</div>

Hey everyone, thanks for looking in

I have a dataset which contains Worker’s details.  
This dataset needs to be filtered by the person booking based on location and product so I can find the right contact details for the worker responsible for that.

```javascript

import { currentMember } from 'wix-members';
import wixData from 'wix-data';

$w.onReady(function(){
    $w('#repContactsDataset').onReady(function(){
        $w('#repContactsDataset').setFilter(wixData.filter())
PreLoadMemberData()
})
})

//Lets get the member and load the info
function PreLoadMemberData (){
currentMember.getMember()
    .then((member) => {
        const memberEmail = member.loginEmail
        const memberName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
        const memberPhone = member.contactDetails.phones[0]
        const memberLocation = member.contactDetails.customFields["custom.preferred-location"].value
        
$w('#inputName').value = memberName
$w('#inputEmail').value = memberEmail
$w('#inputPhone').value = memberPhone
$w('#dropdownLocation').value = memberLocation

    //check console

console.log ($w('#dropdownLocation').value)
console.log ($w('#dynamicDataset').getCurrentItem().title)
console.log ($w('#repContactsDataset').getCurrentItem())
    
    //now filter and find the one i need. Note that the location is confusingly saved under "title" in my dataset
        $w('#repContactsDataset').setFilter(wixData.filter()
        .eq("title", $w('#dropdownLocation').value)  
        .eq("product", $w('#title').text)
    )

console.log ($w('#dropdownLocation').value)
console.log ($w('#dynamicDataset').getCurrentItem().title)
console.log ($w('#repContactsDataset').getCurrentItem())

    })
  .catch((error) => {
    console.error(error);
  });

}

```

When i do this the console shows that the wrong product is the current item and i get the wrong product rep details.  
Any idea why this is happening? Have been trying to figure this out for hours

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [March 7, 2023, 5:54pm UTC](https://forum.wixstudio.com/t/using-code-to-filter-dataset-not-working/3887/2 "2023-03-07T17:54:14Z")

</div>

I’m not sure if this is the only issue, but one problem I am seeing right away is that you are stringing .eq() together when I think you mean to use .and()

like  
query eq XX title AND xzy product…

Take a look at the query docs for and and see if that helps [https://www.wix.com/velo/reference/wix-data/wixdatafilter/and](https://www.wix.com/velo/reference/wix-data/wixdatafilter/and)

---

<div class="post-metadata">

**Author:** ![miran-stubican](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/miran-stubican/32/36638_2.png) [@miran-stubican](https://forum.wixstudio.com/u/miran-stubican)\
**Post date:** [March 11, 2023, 3:22am UTC](https://forum.wixstudio.com/t/using-code-to-filter-dataset-not-working/3887/3 "2023-03-11T03:22:26Z")

</div>

Managed to do a work-around using the query function rather than filter! thanks for the reply!
