cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
F4b
Helper I
Helper I

Select newest record in an associated gallery when it's created

Hi everyone,

I 'm a beginner on PowerApps (no background as developer) and I (still) have a problem with the application I'm trying to create. The purpose of the application is to manage quotes ("devis" on screenshots) including product lines ("lignes de produits/services").

 

On screenshots:

  • On the left, a gallery (Gallery7) displays the list of quotes
  • On the top right, a detail form (FormViewer2) shows the information of the quote selected in Gallery7
  • On the bottom right, a gallery (Gallery7_3) shows the information of Product lines associated to the quote selected in Gallery7 (and display on FormViewer2)

The workflow is to create a new quote with "+" button (a pop-in appears) and then add one or more Product Lines to that Qote.


My problem is that after creating a new quote, it isn’t automatically selected in Gallery7.

 I read other posts on this forum and I tried to do it with a variable (something close to that: https://blogs.msdn.microsoft.com/carlosfigueira/2017/10/04/decouplingbrowsegalleryfromforms/). It works (information of the last created quote appears in FormViewer2), but product lines don't add up properly: they add to the quote selected when the new quote is created (instead of adding to the newly created quote).

 
Do you have an idea to solve my problem?
 

P.S. : I hope to have been clear. As you have probably noticed, English isn't my native language Smiley Wink


Association betwin multiple product lines and a quote

Form2_2.OnSuccess (create or modify quote form) :
Set(
CurrentSelectionedQuoteRecord;
Form2_2.LastSubmit
)
Icon1_3.OnSelect (adding product line button): Select(Icon3_5);; Relate( CurrentSelectionedQuoteRecord.'Lignes de produits / services'; Patch( 'Lignes de produits / services'; Defaults('Lignes de produits / services'); { mso_name: TextInput2_19.Text; mso_price: TextInput2_18.Text; mso_quantity: TextInput2_17.Text; mso_total: TextInput2_16.Text } ) );; Refresh('Lignes de produits / services');; Reset(TextInput2_16);; Reset(TextInput2_17);; Reset(TextInput2_18);; Reset(TextInput2_19)


Screenshots :
Capture.3.PNG

Capture4.PNG

12 REPLIES 12
iAm_ManCat
Super User II
Super User II

Hi,

 

I've done a test to try solve this and was able to resolve it:

 

So first we sort that Gallery7 descending (newest to oldest), which I see you've done, then we have the Default for that item use the First record of that datasource when sorted descending:

 

Default of Gallery7:

First(SortByColumns(QuotesDataSource, "ID",Descending))

This then chose the most recent submission and Selected it as the default item after submitting and refreshing.

 

Cheers,

ManCat

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


Hi @iAm_ManCat !

Thank you very much for your answer !

I confirm that the gallery is sorted from the most recent to the oldest :

Gallery7.Items : SortByColumns(Devis_1; "createdon";Descending)

 

I tried your solution : 
Gallery.Default : First(SortByColumns(Devis_1; "mso_numerodedevis";Descending))
"mso_numerodedevis" is the quote number.
sadly, it didn't work. is the "ID" in your solution is the quote number? My mistake is maybe here.

Again, thanks a lot ! 

 

Ok, not a problem - ID is the SharePoint row ID (it's unique), however we can use the created on value you used:

 

First(SortByColumns(Devis_1; "createdon"; Descending))

 

Could you give that a try and let me know what happens when you do?

 

Thanks,

ManCat

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


It doesn't work either.
The selected record remains the same as before the creation of the new quote (if a record was selected before).

Can you confirm that the new item is showing in the gallery, but that the old item is still selected? If yes, can you please share the formula for Default for that Gallery?

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


I misspoke : only the second last record is selected (the last when the new form is submitted).

when a record is already selected before submitting the new form :
Capture9.PNG

when no record is selected before submitting a new form :
Capture10.PNG

Thanks, can you share the Formula for your Default within that left-side gallery please 🙂

And can you please confirm the DataSource for that Gallery 🙂

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


 

Here : 

Gallery7.Default = First(SortByColumns(Devis_1; "createdon"; Descending))

 

the datasource is indicated in "item", right ? In this case, it's : Devis_1 (=quote).

 

Can you create a table, and then have it display what we are trying to show as a default (in the same way we would use a label for troubleshooting, but this time we want it to show the record)

 

First(SortByColumns(Devis_1; "createdon"; Descending))

This should help us better understand what it's doing, and why it's not working for a Default item - maybe it can't find it, or maybe it couldn't sort by createdon or maybe it wants it in a different format

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


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

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

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

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (82,305)