How to add value to enum array for record?
![Anna Sho](https://us.v-cdn.net/6037124/uploads/userpics/9J2BDR93V3FA/nAMOURF2V6E1B.jpeg)
User can have multiple roles = user, editor, reviewer etc so role is array []
I want to update user record and add one more role. I get user with existing roles and try to add new one to that array.
I get error. How to fix it?
Answers
-
Pay attention to the
text
label on top ofuser.role
. It tells that Xano is treating the value as text. But on the left siderole
has a labelenum[]
. You are trying to push a value to a text string not to an array. I suggest you to open the dropdown menu and select CONST → array to change thetext
label forarray
while keeping theuser.role
there. Then you shouldn't have problem pushing the valueeditor
which is an allowed value by the enum field. -
The way edit record works is that it replaces the old value with a new value. So what you want to do is push an item to the list, but what it needs is to be told what the new version of the list is. To solve this, first use "get record" to find out the current value. If the get record returns something called "user_1", then we will work with "user_1.role". So what you want to do in your edit record is set that value to user_1.role with a filter of push and your added value.
That 2-step process (get + edit) is a frequent requirement for managing the complex data types (object, array, json) when the goal is making a change (adding an item, altering a key, etc). Getting past this hurdle puts you in great position to be a Xano power user!
We work on xano function stack questions all the time as part of our focus on the "hardest 5%" in daily office hours at State Change. -
Thank you Arturo & Ray.
It didnt work for me. just to get user record and add user.role as it is array..
When i select user.role it turns to "text". If I select → array in dropdown it reverts to empty []. Maybe I do something wrong I dunno.
But I have found workaround that works. I thought it would be less steps))
-
@Anna Sho I've tested your case and had the same problem with enum lists. Throws the "is not one of the allowable values" error every time you try to update the
enum[]
field no matter how you do it.One workaround that I tested positively is to change the
enum[]
field type for atext[]
type. You lose the automatic value restriction, but you con go on.Maybe @Ray Deck knows how to deal with
enum[]
fields better.This example below works well even with the warning…
-
I've struggled with this as well, typing in an array as JSON would convert the value to text somehow, had to use "Push" action, too.
That was so unstraightforward - I had expected to simply select the allowed enum values, but no.
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