Copying data from one table to another

Howdy folks,

I'm super new here, so I appreciate your support!

I would like to create an internal tool that will copy the rows from a table called user_project which hosts data for users to which projects they have access too.

My goal is to copy the rows from that table and filter it by the userID to a target userID with the same access level. I would like to copy access from one user to another.

I built an input field to input the userID with the access I would like to copy and another input field to the target userID to which the access should be given.

I'm stuck in the part where I will need to copy the rows from the original user to the new user; any help will be greatly appreciated!

Hey @ran! Definitely happy to help here. When you say copy do you mean to your clipboard or to the database?

Also, any screenshots you can share of your current setup would be much appreciated :pray:

1 Like

Hi, @victoria; thanks so much!!!

Here is a simple screenshot of my setup:

I removed some data :slight_smile:

Basically, on the left-hand side, I input the user where I want to copy the lines from, each line representing access to a project. In contrast, on the right-hand side, I have the target userId, e.g., the user that will get the same level of access to the projects of the user from the left.

My goal is to use the button to copy the lines from the left user to the right user.

Got it! And do you update a database at any point or do you just want to display the value on the right table?

Hi @victoria I would like to update the DB so that the lines from the left table will be added to the right table (but not remove the existing lines in the right table)

Sounds good! Would something like this query work for you? It's a bulk insert query that inserts the selected rows from table1 into the underlying database populating table2. It also runs the underlying query (getProjects) on success to make sure that the data showing in table2 is updated/accurate.

Let me know if this works or if you have any questions!

HI Victoria, thank you for your reply!

QQ - in my scenario, both of the tables are the same table in the DB, user_project, and they are filtered per the user input.
How can I make sure that I'm moving the data from the left-sorted table to the right one? Maybe I think that the GUI mode is not the right approach and maybe to write it in SQL?

Oh, same table! That should also be fine to write in either the GUI mode or SQL mode as long as you modify the records to insert to match the intended IDs.

For example, I'm giving the new row a new ID so when we insert it into the same table, the info will be linked to the new ID:

{{ => Object.assign(obj, {id: numberInput1.value}))}}

Thanks, @victoria

Can you also assist me in the syntax to get the value of a specific cell inside the table?

For example, if I want to get the value of the quantity column (in your above image), how do I do that?

Hey @ran! Definitely.

If you want a cell from the selected row, you can do something like:

{{ }}

Or do you want to pick a different cell?

1 Like