cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RoScha
Helper V
Helper V

select a data record in the gallery by command

Hello community,

there is a command in Powerapps that allows me to select a certain data record in the gallery using a formula so that it can be used in another place in another screen, e.g. the command galleryxyz.selected ... works?

 

Is that possible?

Thank you for your help.

 

Best regards

RoScha

2 ACCEPTED SOLUTIONS

Accepted Solutions
Pstork1
Dual Super User III
Dual Super User III

I don't think there is a way to do this using a command.  The Select() function points to a control on screen, not a record.  The common usage is Select(Parent) in a gallery to select the control that hosts a specific record in a gallery.  But I 've never seen a way to do this other than from inside a gallery.

 

However, in most places where you would use the Gallery.Selected property to refer to a specific record you can also do a Lookup() to get a specific record.  So I think the workaround would be programmatically set a variable that contains an index value for the record from the data source and then do a lookup on the data source or gallery to get the record, rather than selected.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

RandyHayes
Super User III
Super User III

@RoScha 

Yes, the GalleryX.Selected will refer to the currently selected record in the Gallery.  This may change based on actions within your app though.  If you need to take a snapshot of the record at the time of selecting a record, then I would utilize a global variable to capture the currently selected item and not rely on the .Selected property of the gallery.  This, again, will depend on your app.

 

As for selecting a specific record by default, then you can utilize the Default property of the Gallery to do this.  Internally, PowerApps will maintain the current selection unless the underlying datasource is changed and it impacts the Items property significantly (i.e. there is more to your Items formula than just a datasource).  In that scenario, you would need to provide logic in your Default property of the Gallery to lookup the record you want (and it must match EXACTLY to the record schema of the Items property).

 

The other thing you can utilize is the Select function.  For Select, you can, for example, do Select(yourGallery, 3) this will select the 3rd item in your Gallery.  The unfortunate part of that is that you really never know the item position of any of your gallery items to effectively select the right one...but in some cases you can surmise the correct row.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

3 REPLIES 3
Pstork1
Dual Super User III
Dual Super User III

I don't think there is a way to do this using a command.  The Select() function points to a control on screen, not a record.  The common usage is Select(Parent) in a gallery to select the control that hosts a specific record in a gallery.  But I 've never seen a way to do this other than from inside a gallery.

 

However, in most places where you would use the Gallery.Selected property to refer to a specific record you can also do a Lookup() to get a specific record.  So I think the workaround would be programmatically set a variable that contains an index value for the record from the data source and then do a lookup on the data source or gallery to get the record, rather than selected.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

RandyHayes
Super User III
Super User III

@RoScha 

Yes, the GalleryX.Selected will refer to the currently selected record in the Gallery.  This may change based on actions within your app though.  If you need to take a snapshot of the record at the time of selecting a record, then I would utilize a global variable to capture the currently selected item and not rely on the .Selected property of the gallery.  This, again, will depend on your app.

 

As for selecting a specific record by default, then you can utilize the Default property of the Gallery to do this.  Internally, PowerApps will maintain the current selection unless the underlying datasource is changed and it impacts the Items property significantly (i.e. there is more to your Items formula than just a datasource).  In that scenario, you would need to provide logic in your Default property of the Gallery to lookup the record you want (and it must match EXACTLY to the record schema of the Items property).

 

The other thing you can utilize is the Select function.  For Select, you can, for example, do Select(yourGallery, 3) this will select the 3rd item in your Gallery.  The unfortunate part of that is that you really never know the item position of any of your gallery items to effectively select the right one...but in some cases you can surmise the correct row.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

Hello @Pstork1 

hello @RandyHayes 

 

Thank you for your answers.

 

Best regards

RoScha

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (78,813)