I have a simple dynamic query that I want to run that is giving an error. It gets the _id and email address of the current logged in user and then matches the email to a reference field of email in another collection that is connected to the #membersdataset.
The console output for both userId and email are correct as expected, but when I try to run the filter, i get:
"An error occurred in one of currentIndexChanged callbacks DatasetError: could not resolve dynamic filter"
Anyone have any thoughts? It looks pretty straightforward so I am not sure why it isn't working.
import wixUsers from 'wix-users'; import wixData from 'wix-data'; $w.onReady(function () { let userId; userId = wixUsers.currentUser.id; wixUsers.currentUser.getEmail() .then((email) => { let userEmail = email; console.log(userId) console.log(userEmail); $w('#membersdataset').setFilter(wixData.filter().eq('email', userEmail)) }); })
Are you using onCurrentIndexChanged( ) in your code anywhere?
Calling onCurrentIndexChanged() on a write-only dataset causes an error.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#onCurrentIndexChanged
Is your Members dataset write only as that can cause an error too (I am assuming that it would actually be set to read and write, however just checking).
Calling setFilter() on a write-only dataset causes an error.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFilter
Also, look at the Wix Users API reference for the id function.
https://www.wix.com/corvid/reference/wix-users.html
https://www.wix.com/corvid/reference/wix-users.User.html#id
it could be something simple like your .then call (a promise) breaking the setFilter call, however you will need to rework your code to check it and solve that issue if it is that.
Have a read about working with promises here.
https://support.wix.com/en/article/corvid-working-with-promises