Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

[Solved] Dynamic buttonAsync labels and values?

Topic Labels: Scripting extentions
Solved
Jump to Solution
708 2
cancel
Showing results for 
Search instead for 
Did you mean: 

Can the buttonAsync be created dynamically?

I have an array of Order Numbers called filteredOrderNames. Can each value of the array serve as the button label?

let selectedOrder = await input.buttonsAsync(
'Select Order Group from List below',
[
    {label: filteredOrdersNames, value: filteredOrders}
]);
1 Solution

Accepted Solutions

Yes, this can be done using the map method on the filteredOrdersNames array. Here’s a test I just ran:

let filteredOrdersNames = ["One", "Two", "Three", "Four", "Five", "Six"];
let filteredOrders = [1, 2, 3, 4, 5, 6]

let selectedOrder = await input.buttonsAsync(
    "Select order group from list below",
    filteredOrdersNames.map(item => {return {label: item, value: filteredOrders[filteredOrdersNames.indexOf(item)]}})
)

output.text("Selected Order: " + selectedOrder)

Output:

Screen Shot 2020-09-07 at 9.25.25 PM

See Solution in Thread

2 Replies 2

Yes, this can be done using the map method on the filteredOrdersNames array. Here’s a test I just ran:

let filteredOrdersNames = ["One", "Two", "Three", "Four", "Five", "Six"];
let filteredOrders = [1, 2, 3, 4, 5, 6]

let selectedOrder = await input.buttonsAsync(
    "Select order group from list below",
    filteredOrdersNames.map(item => {return {label: item, value: filteredOrders[filteredOrdersNames.indexOf(item)]}})
)

output.text("Selected Order: " + selectedOrder)

Output:

Screen Shot 2020-09-07 at 9.25.25 PM

This is brilliant! Thanks so much. It works perfectly.