Showing choices from table records and get the sel...
# 🤝help
n
I have a single choice input field where the choices are populated from a table which has name and id columns, but the user choose one of them I Want to be able to query the table based on that selection, but the problem is you can get table row using ID only and I want to show the user a name where they select from, in other world we would have for each choice a value and a label where label is what is shown but value is what is stored, how I can achieve this here
e
Hey @numerous-parrot-82549, so you have a table with several rows, each row should be an option? And then what should happen when the user selects an option?
n
Hey @early-train-33247 the user will select a name, I want to do something like this select * from table where name = selected_name;
e
1st step - create a users table

https://cdn.discordapp.com/attachments/1135631937868939386/1135659500855103709/image.png

Is it similar to what you have?
2nd - add a Find Records card (with no selector if you want to get all) that saved the results to a variable called foundUsers

https://cdn.discordapp.com/attachments/1135631937868939386/1135660294455185539/image.png

3rd - create an array variable called userOptions 4th - add an Execute Code card below the Find Records card, with the label "creates user options" and the following code:
Copy code
js
workflow.userOptions = workflow.foundUsers.map((user) => {
  return { label: user.Name, value: user.id }
})
n
1- it's similar yes
yup I have this already
I have this piece of code to map the array of json to array of names
Copy code
@clients_list .map((item) => item.name);
e
Yeah use my code instead
n
ahhh
so we can return object of label and value
that's exactly what I needed,
just for my own learning, how I can get such info on my own ?
e
It's not on the docs yet, but I have asked the team to add it!
n
I got it from here
e
5th - add a Single Choice card that saves the result to a
desiredUserId
number variable and use the
userOptions
variable in the Items section

https://cdn.discordapp.com/attachments/1135631937868939386/1135662896974680236/image.png

n
I will use the value to chosen + get element
I was confused about label vs value thing
e
Amazing! I'm gonna keep going for other users that might come across this!
6th - create a object variable called
desiredUserDetails
7th - add a Get Record card that uses the
desiredUserId
variable to find the record, and saved the result to the
desiredUserDetails
variable

https://cdn.discordapp.com/attachments/1135631937868939386/1135663781582745751/image.png

8th - add a Text card (or whatever type you like) to display the user details

https://cdn.discordapp.com/attachments/1135631937868939386/1135665097767931945/image.png

That's it, by following this process you will be able to show options based on a table's records, and show one specific record details! Take note of these things: * The case of the column names matters when trying to read or write to them * The createdAt and updatedAt will always have that name and they represent a date in the ISO format, which you can convert to a more readable format like this:
luxon.DateTime.fromISO(workflow.userDetails.createdAt).toLocaleString()
* It's not good UX to show the user a list with more than 3 options (generally speaking), so try to cut them down!
86 Views