Help

[Solved] Dynamic buttonAsync labels and values?

Topic Labels: Scripting extentions
Solved
Jump to Solution
2636 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Chris_Guthrie
7 - App Architect
7 - App Architect

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
Justin_Barrett
18 - Pluto
18 - Pluto

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

3 Replies 3
Justin_Barrett
18 - Pluto
18 - Pluto

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.

NanMel
5 - Automation Enthusiast
5 - Automation Enthusiast

4 years later and this post helped me out SO much! Thank you!