# Nesting setFilter() within a promise

**URL:** <https://forum.wixstudio.com/t/nesting-setfilter-within-a-promise/20530>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 9, 2019, 7:55pm UTC](https://forum.wixstudio.com/t/nesting-setfilter-within-a-promise/20530 "2019-05-09T19:55:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![beyondobediencetrain](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/beyondobediencetrain/32/9248_2.png) [@beyondobediencetrain](https://forum.wixstudio.com/u/beyondobediencetrain)\
**Post date:** [May 9, 2019, 7:55pm UTC](https://forum.wixstudio.com/t/nesting-setfilter-within-a-promise/20530/1 "2019-05-09T19:55:22Z")

</div>

I have a dataset that will be filtered in different situations. I’d like the flexibility to be able to use .then. ie:

onClick(){  
TestFilter(1)  
.then(() =\>{  
TestFilter(2);  
});

So one sort doesn’t risk overriding the other. With the code below, I’m getting the following error: “An error occurred in one of currentIndexChanged callbacks DatasetError: could not resolve dynamic filter”. Other operations work fine if I substitute them for the setFilter code, but something about the promise seems to be breaking setFilter. Any ideas?

```javascript
function TestFilter(){   
     return new Promise((resolve, reject) => {
         console.log("passed return");
         $w("#GroupClasses").setFilter(wixData.filter()
            .eq("date", $w("#cDLog").value) button click
            .eq("title", $w("#cTLog").value)  
        )
        .then(() => {
            console.log("Dataset is now filtered");
            var count = $w('#GroupClasses').getTotalCount();
            console.log(count + " items found");
            console.log($w("#GroupClasses").getCurrentItem());
            resolve("sorted")
        })
        .catch((err) => {
            //$w("#empty").show();
            reject("error message: " + err);
        });
        });
}

```
