cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
KickingApps
Level 8

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
Power Apps Staff CarlosFigueira
Power Apps Staff

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
Power Apps Staff CarlosFigueira
Power Apps Staff

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
KickingApps
Level 8

Re: Is it possible - Set a variable from collection

Thanks Carlos; info was very helpful.

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (4,878)