Jun 07, 2020 12:22 PM
Hello,
I have a field where I have a list of collaborator. I’m developping a block and I would like to get all the users ID from my field of my table.
Currently I can get the name of the collaborator with :
const base = useBase();
cont table = base.getTableByNameIfExists(“name_of_the_table”);
const value_user = my_record[0].getCellValueAsString(“Name_of_collaborator_field”);
I got the name of all my users in the value_user
But now, I would like to get the list of user ID. How can I got it ? Thank you :winking_face: .
Viken
Solved! Go to Solution.
Jun 07, 2020 01:57 PM
Hi @Viken_Toramanian - you can just use my_record[0].id
to use the unique user id within Airtable. Here’s my script to log them all out (for all records):
let table = base.getTable('Table');
let query = await table.selectRecordsAsync();
for (let record of query.records){
let collaborators = record.getCellValue('Collaborators');
if (collaborators) {
for (let collaborator of collaborators) {
console.log(collaborator.id)
}
}
}
Jun 07, 2020 01:57 PM
Hi @Viken_Toramanian - you can just use my_record[0].id
to use the unique user id within Airtable. Here’s my script to log them all out (for all records):
let table = base.getTable('Table');
let query = await table.selectRecordsAsync();
for (let record of query.records){
let collaborators = record.getCellValue('Collaborators');
if (collaborators) {
for (let collaborator of collaborators) {
console.log(collaborator.id)
}
}
}
Jun 08, 2020 04:34 AM
Hi @JonathanBowen,
It works perfectly ! Thank you :thumbs_up:
I just adapt it and use selectRecords() instead of selectRecordsAsync(), because I have a function which is checking if my user is part of field “collaborator”. If I use selectRecordsAsync() the function will not check on time the condition and it will not considere if the user is part or not part of the field “collaborator”.
Thank you again for your help.