cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Skilled Sharer
Skilled Sharer

Is it possible - Set a variable from collection

Suppose I have a collection of variables.  Is it possible to set the variables based on the values in a collection via a Button and the Select function? A bit of an out there question, I realize.  

Collect(
    colTestVariable,
    {
        id: "1", formula: Set(gloIsTrue, true)
    },
    {
        id: "2", formula: UpdateContext({varShowImage:true})
    }
)

Button
Select(Lookup(.....)  or
Select / If 
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Power Apps
Power Apps

Re: Is it possible - Set a variable from collection

Not really - collections can only store data, not actions or behaviors. You can store some code in the collection, and then execute the logic on a button press. For example, if you have this collection in a gallery:

ClearCollect(
    colTestVariables,
    { id: "1", name: "Set global gloIsTrue" },
    { id: "2", name: "Set context varShowImage" })

You can have a button outside the gallery that takes action based on the selected item:

Switch(
    Gallery1.Selected.id,
    "1", Set(gloIsTrue, true),
    "2", UpdateContext({ varShowImage: true })
)

Hope this helps!

View solution in original post

2 REPLIES 2
Highlighted
Power Apps
Power Apps

Re: Is it possible - Set a variable from collection

Not really - collections can only store data, not actions or behaviors. You can store some code in the collection, and then execute the logic on a button press. For example, if you have this collection in a gallery:

ClearCollect(
    colTestVariables,
    { id: "1", name: "Set global gloIsTrue" },
    { id: "2", name: "Set context varShowImage" })

You can have a button outside the gallery that takes action based on the selected item:

Switch(
    Gallery1.Selected.id,
    "1", Set(gloIsTrue, true),
    "2", UpdateContext({ varShowImage: true })
)

Hope this helps!

View solution in original post

Highlighted
Skilled Sharer
Skilled Sharer

Re: Is it possible - Set a variable from collection

Thanks Carlos; info was very helpful.

Helpful resources

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,350)