How do I use a Precondition with an Array?
![Patopt](https://us.v-cdn.net/6037124/user_avatars/5034377.jpg)
I'm trying to write some permissions into my application, simply put getting a list of users who are allowed to edit a record. I have a basic list of users stored in array who have access, and I want to enforce a precondition that says if the users_id trying to edit the record is in the array, then they can edit.
The problem I'm running into is that I don't see any array functions for validating data exists within a precondition, I'm only seeing basic mathematical operators.
Does anyone know how to go about achieving this?
Best Answer
-
Almost @Patopt - remember, you don't want to evaluate if "true" is in your array but rather the user_id input. So you'll want to move the filter to the other side.
Answers
-
Hi,
Yes, the arrays don't have some of the operators available in queries.
From the top of my head I can think of a solution like this:
create an array with only one element which is the user_id then create another variable and use intersect filter on the newly created array and the one in which you want to check, if it's empty then your id is not in the second array and based on that condition you can create some further actions. -
Hi @Patopt - you will want to use the IN filter to say if your value is IN the array and set it equal to true/false. Some query operators move into filters outside of the query. IN is an example of this.
WHERE
input: user_id | IN | var: flow_editors == true
-
Something like this? Just tried and looks like precondition is not catching the condition, everything just goes through.
-
Thank you!
-
For anyone that wants to use preconditions with arrays and true doesn't, try replacing the true bool with null.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback