Jul 13, 2024 02:04 PM
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
Then I make an array from just the names:
let yearNames = schoolYears.map(record => ({name: record.name}))
console.log(yearNames)
Which gives:
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.
Solved! Go to Solution.
Jul 13, 2024 06:31 PM
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
Jul 13, 2024 06:31 PM
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
Jul 13, 2024 06:39 PM
Excellent! Thank you.