[Solved] Dynamic buttonAsync labels and values?

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

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

2 Likes

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

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.