I suddenly can’t figure out how to filter collections by variables. I could have sworn that I was able to set this up properly previously, but now I’m not getting any data when applying a filter based on dropdown selection value.
I recorded a Loom to show what I mean:
I’d really appreciate help with this - it’s something that I’ll need to do in multiple places throughout my app.
Now that I’ve spent more time in my editor, it seems as though multiple filters that were working recently are no longer working. Was there an update to the system that might have caused this?
Ok, while this works technically, there is a big problem. When I use “toText” to see if a value is contained in an array, it is literally just looking to see if the array contains that character. So, if the selection value is “3”, records with 3, 13, 30 in the array are resulting!
I can’t do that in this case because I am filtering by an array. So if a record has [3, 14, 45], and the dropdown value is 3, I want to display that record. For that reason, the “is exactly” filter option doesn’t work.
You have a drop down with the value of employee id’s, and you want to select that drop down, and have the collection only show the locations that the employee is attached to?
Yes, that’s part of the json structure. But to make it even simpler, I am just looking to filter by the equivalent of the location ids, and I created another array in each record with just the ids in an array. So, using your above example,
I’m not sure how I would do that? I’m trying to filter a collection called users. Each user has a field called “justroles” which lists the ids of the roles the user has. I want to use a dropdown to filter the collection to only show users that have a certain role.
So, if the value of the dropdown is 3, and the collection items include:
For now, I am using a formula to selectively display individual list items that have the selection value in their justroles array. That’s imperfect, possibly for more reasons than I realize currently, but at least it is achieving the main goal for now.
This might be an imperfect solution also…. It looks like you’re using Xano…
An easy solution would be to supply the role name as an addon in the justroles array.
Do you have the role name as the display? then filter by the display field instead of the id, using the contains in the array. Then you wouldn’t have the problem of getting 13 if you only want 3.
I’ll think about another solution, but that could work if you can supply more data through the endpoint.
Ah! Okay… I’m pretty sure this can be done with those array filter functions…
but, there’s also this solution… it’s kind of convoluted. I’m not near a computer to do this, but here it is incase you want to try now.
Use a workflow. When dropdown value changes.
Create a variable called users-with-role that is an array.
Use a loop in the dropdown workflow to loop through the users, and then a nested loop to go through the array of roles.
Use an array function to determine if the selected role id is in the array. If it is, place that parent user id into that users-with-role variable.
Then in your api endpoint, I would handle the querying. Supply that array of users to the api endpoint in your collection, and send back the correct users.
Refetch the collection at the end of the workflow.
If no array is supplied to the endpoint, have the array send back all the users that you initially wanted.
Again, I think there is an easier answer, but that would work.