Help

Re: Get User ID from field - Block

Solved
Jump to Solution
1066 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Viken_Toramania
5 - Automation Enthusiast
5 - Automation Enthusiast

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

1 Solution

Accepted Solutions
JonathanBowen
13 - Mars
13 - Mars

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)
        }        
    }
    
}

If this answers your question please consider marking this as the "solution". If not, please post again for more help. Thanks!

See Solution in Thread

2 Replies 2
JonathanBowen
13 - Mars
13 - Mars

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)
        }        
    }
    
}

If this answers your question please consider marking this as the "solution". If not, please post again for more help. Thanks!

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.