cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MelissaReed
Frequent Visitor

How to set Gallery.Selected to the just-added SP list Item that was created via a PowerAutomate call (and returns the new Item ID)

How do I accomplish the equivalent of

          Set(Gallery1.Selected, Lookup(Gallery1,ID=NewItemID))

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) 

MelissaReed_1-1605013863021.png

 

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:

  • Refresh() does pick up the new record but doesn't change Gallery.Selected
  • Gallery.Default Lookup() has been suggested,  but this had no effect.    ScanRequests is the SP List that populates Gallery1, NewItemID is a numeric value returned from the PowerAutomate cloning call.  (I hardwired its value to for testing)
    • LookUp(ScanRequests,ID=NewItemID)
  • Gallery.Default Filter() has been mentioned but I don't want to eliminate all other records.   
  • I saw Navigate() suggested, but a) I'm already on the screen I want to be on, it doesn't appear to set anything.

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.  

5 REPLIES 5
RandyHayes
Super User III
Super User III

@MelissaReed 

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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!
Wayne_A
Advocate III
Advocate III

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?

           Lookup(ScanRequest,ID=NewItemID)

                 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.

 

ClearCollect(LastClone,

    Patch(YourDB/List,

        Defaults(YourDB/List),

        {

            param1: value,
            param2: value,

            param3: value,

        }

    )

)

 

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!

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

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

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

Top Solution Authors
Top Kudoed Authors
Users online (36,471)