Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

use single select field values in input select

Topic Labels: Scripting
Solved
Jump to Solution
1107 2
cancel
Showing results for 
Search instead for 
Did you mean: 
auekk2787
7 - App Architect
7 - App Architect

I'm trying to use the options from a single select field as an 'input' selection in my script. I'm not sure if Airtable allows this. So far I have:

 

let selectTable = base.getTable("Courses");
let selectField = selectTable.getField('School Year');
let schoolYears = selectField.options.choices;

console.log(schoolYears)

 

Which provides 

auekk2787_0-1720904542160.png

Then I make an array from just the names:

 

let yearNames = schoolYears.map(record => ({name: record.name}))

console.log(yearNames)

 

Which gives:

auekk2787_1-1720904583710.png

I'd like to then use those choices as an input:

 

let selectYear = await input.buttonsAsync('Pick a year', [yearNames]);

 

But this gives an error that you need a string. 

Would this be possible to use? It seems to want a full object literal list and not a variable like this.

 

1 Solution

Accepted Solutions
TheTimeSavingCo
18 - Pluto
18 - Pluto

Try this:

let selectTable = base.getTable("Courses");
let selectField = selectTable.getField('School Year');
let schoolYears = selectField.options.choices;

let yearNames = schoolYears.map(x => {
    return {label: x.name, value: x.name}
})

let selectYear = await input.buttonsAsync('Pick a year', yearNames);

Here's a link to the documentation for the expected format for buttonAsync: https://airtable.com/developers/scripting/api/input#buttons-async

See Solution in Thread

2 Replies 2
TheTimeSavingCo
18 - Pluto
18 - Pluto

Try this:

let selectTable = base.getTable("Courses");
let selectField = selectTable.getField('School Year');
let schoolYears = selectField.options.choices;

let yearNames = schoolYears.map(x => {
    return {label: x.name, value: x.name}
})

let selectYear = await input.buttonsAsync('Pick a year', yearNames);

Here's a link to the documentation for the expected format for buttonAsync: https://airtable.com/developers/scripting/api/input#buttons-async

auekk2787
7 - App Architect
7 - App Architect

Excellent! Thank you.