Append Record to List (Xano)

I have a table TEAMS and another table USERS. Each TEAM record can have multiple USERS.

I’m trying to add an action where I can click on a user and add them to a team, appending them with all of the other users already on the team. Right now when I call the record it’s just overwriting any other users already on the team and adding just that one user I select.

Any idea on how to make this work?

Backend is Xano

You could try using the add or prepend formulas to add the current user at the end of the array of users you have in Xano:

When you hover over a formula, you can see a tooltip on how it works.

Let us know if that solves the issue.

Thanks I will give this a shot and let you know how it works.

1 Like

OK so I tried to make this work, but it’s just replacing whatever value is in the field, not adding anything to it. Am I doing something wrong with my Array?

image

Show Team[‘data’][0][‘users_id’] is not an array. This is the value of the users_id key.

Item.data[‘id’] is not an object. This is the value of the id key of the current item in the collection.

if you want to add the object to the array/collection, try this: add(show Team,Item.data)

Thanks Kevin.

So I wanted to add users to the users_id column, wouldn’t I need to specify the column that row/column I want to add the users to?

What is the structure of the array that you are wanting to add the team member to?

Is it like this?

Show Team = [
{“users_id”:1},{“users_id”:2}
]

And you want to make it like
Show Team = [
{“users_id”:1},{“users_id”:2}, {“users_id”:6}
]

Or maybe it’s like this?
And you want to make it like
Show Team = Id,…,users_id:[5,8,6,97]

Here is the JSON back from the table TEAMS w/relationship of USERS

@patopt

So that I understand correctly … are you just wanting to add the user to the Show Teams array on the front end? Or are you wanting to add the user in the backend Xano?

If you want to add it to the backend, you will need to handle that in the Xano API endpoint. In that scenario you’d want an endpoint that takes the team_id and the user_id as inputs, and then does a database transaction where Xano adds a new record to the DB to indicate a new user on the team.

If you just want this to happen on the front end, you can use the array functions @Joyce mentioned above. However, adding a user on the frontend using those functions will not add them to the database.

If you want to add a user to the JSON schema from your screenshot on the frontend, you will want to use something like add(Show Team[‘users_id’], {id:2,email:“john@aol.com” … first_name:“John”,etc,etc})

The JSON above for users_id is going to expect an object of type user.

Let me know what exactly you are wanting to do and I can provide some more input.

Thanks Kevin. I’m looking at adding users in the Xano backend, I just want to update the row/column to add users to that object in the database.