How do I accomplish the equivalent of
so that when I create a copy/clone of the Gallery.Selected item, the Gallery.Selected gets changed to that just-created item.
Here's the scenario:
I have a Screen with a Gallery (pulled from a SP list) and Viewform of the Gallery.Selected item.
There's a Clone button on that form (circled in yellow)
When that Clone button is clicked, in CloneItem.OnSelect calls PowerAutomate which creates a copy of that record and returns the ID of the new record just created. That all works just fine.
What I can't get it to do is change the Gallery1.Selected to "repoint" to the new record. Here are some of the things I've tried:
So after a new record is added to the Sharepoint list, how can I get the Gallery to shift its Selected value to the newly created record?
How do I accomplish this: Set Gallery1.Selected = true where ID=NewItemID?
If you need me to "say more about what you're trying to do", please be specific about what additional information you need.
In this case (since you are creating the record outside of PowerApps in PowerAutomate) you will need to first refresh the datasource in order for PowerApps to see it.
Then you will need to utilize the Default property of the Gallery to select the record. The key thing to keep in mind is that the record you LookUp in the default MUST match the signature of your Items property of the Gallery.
So, if your Items are simply the datasource, then you can use a straight lookup in the Default. If you are altering the items in any way in the Items property, then you will need to alter the record equivalently in the Default.
Ex. if you Drop a column in the Items property, then you must Drop that same column in the Default in order for the selection matching to occur.
Also, sometimes (although it seems to be resolved now) the Attachments column creates a conflict that causes the match to no occur...it can be dropped in both the items and the default.
I hope this is helpful for you.
You should be able to do it using a Variable.
When your SP list returns the new ID, use Set(yourVariable,theNewID)
Set the Default property of the Gallery to Lookup(yourDataSource, ID=yourVariable)
The only other thing may be to force the first gallery item to be selected on first use (as is the default anyway in the background for a gallery) - so you could initally set your variable to something like Set(yourVariable,First(yourDataSource).ID) when the screen is first used or somewhere else appropriate.
Thanks for your suggestions. I am anlready doing the Refresh() after returning from the W/F call.
Do I have the syntax correct for Gallery1/Default?
where ScanRequest is the data source, NewItemID is a numeric variable holding the ID of the record just created. No quotes, no brackets? Just this text?
I'm wondering if it's a problem with the attachment column, even if I don't have any documents attached?
Or maybe the problem is the variable is numeric?
I would try to wrap the NewItemID in a Value call just to see if maybe that will fix it. ("Value(NewItemID)") You can highlight NewItemID in the editor and it should tell you the type. For ID it would need to be a number no text. I'm not sure what you have but worth a quick check for sure.
The second thing you can do is save a local copy of the last item that you cloned using clearcollect function. You can do this when you patch a new record.
This would allow you to set the item to First(LastLogin) or look that item up by First(LastLogin).ID.
Yes that's the right syntax for the Default property.
As Scoozi mentions below just check that the NewItemID is the correct data type (which it should be if it's assigned directly from and after the SP list call to create a new item)?
Like it? please click the Thumbs Up button!
Problem Solved? please click the Accept as Solution button to help other Community members find the answer as well!
Check out the News & Announcements to learn more.
Did you know that you can visit the Power Query Forum in Power BI and now Power Apps
Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.
DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.