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

Circular reference in patch control

Hello All,

 

I have a gallery with editable rows and my Data source is SharePoint . I have written a patch function to store the values from gallery to SP. I have a Copy Icon on each row of my gallery to copy that particular item.

 

Here is my copy  item function looks like :

 

 Now, I am adding another screen where on click of a button I am storing all the values of this particular gallery into a collection including this copy Icon function also .

 

So on my New screen I pass the collection into the items property and I am able to get all the values.

Now when I am adding patch function due to the circular reference I am not able to patch , as copy is a control in my previous screen and its not accepting in this screen .

 

 

Collection formula is : Gallery . Selected. All Items

Copy Icon is also stored in the collection as highlighted:

 

AishG_2-Collection.pngAishG_1-Patch collection.pngAishG_0-1633971175973.png

Question : I am able to use defaults in the patch and able to create a record as a new record but then I need to use this record as I Already have a record and I need to update it .

 

Please suggest me any advice to overcome this error .

 

 

 

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

So in my first screen I have a gallery : gallery1connected to a SharePoint and a similar patch function is written and its working as expected . Now I have a Main gallery upon clicking on the button I am creating a collection and getting allitems from gallery1 and on Screen 2 i have a gallery2 and I am passing the collection as items .

So these images are of my Screen 2 where copy is an Icon in my screen1 which is copying item and in the collection also its getting saved . But on my Screen 2 when I patch the collection I am getting this error shown in image 1 . So the ID :ID might not work 

View solution in original post

RandyHayes
Super User
Super User

@AishG 

It is difficult to see the images you have in your post as they are too small and trying to zoom on them they just get blurry.  

But the one thing I can see is that with this extra collection (which again is just extra typing for no need) you are not including the ID.  You should ALWAYS pass around the ID of a record as it is the primary identifier for the record and you will almost always need it.

 

And to follow that statement, if you set your Gallery2 Items to Gallery1.AllItems (or some filtered or derived table from that gallery) then your Gallery 2 will show everything needed - without some extra collection.

Now in your second part of your last response, you are stating that you are trying to then patch some other collection?  What is the purpose of the extra column called Copy?  I'm a little confused on what you are trying to do, but I think you might be over complicating it a bit.  I can't tell for sure as the images are hard to see.

_____________________________________________________________________________________
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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
RandyHayes
Super User
Super User

@AishG 
What is the collection for in your scenario?  Your gallery is already acting as a collection in this case.

There is no need for setting a varRecord and all of the extraneous typing you are doing there either.

 

You can simply set your formula to update your data source directly.

Patch(yourDataSource,
    ForAll(yourGallery.AllItems,
        {ID: ID,
         Title: TextInputx.Text,
         ...etc...
        }
    )
)
         

 

Your pictures are too small for me to read the names of your controls, but the one important part of the above formula is that you utilize the ID.  When you supply the ID, then Patch will know to update the record that matches that ID.  If the row in your Gallery does NOT have an ID (i.e. a new row), then the ID will be blank, and Patch will know to create a record instead of update it.

 

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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

So in my first screen I have a gallery : gallery1connected to a SharePoint and a similar patch function is written and its working as expected . Now I have a Main gallery upon clicking on the button I am creating a collection and getting allitems from gallery1 and on Screen 2 i have a gallery2 and I am passing the collection as items .

So these images are of my Screen 2 where copy is an Icon in my screen1 which is copying item and in the collection also its getting saved . But on my Screen 2 when I patch the collection I am getting this error shown in image 1 . So the ID :ID might not work 

View solution in original post

RandyHayes
Super User
Super User

@AishG 

It is difficult to see the images you have in your post as they are too small and trying to zoom on them they just get blurry.  

But the one thing I can see is that with this extra collection (which again is just extra typing for no need) you are not including the ID.  You should ALWAYS pass around the ID of a record as it is the primary identifier for the record and you will almost always need it.

 

And to follow that statement, if you set your Gallery2 Items to Gallery1.AllItems (or some filtered or derived table from that gallery) then your Gallery 2 will show everything needed - without some extra collection.

Now in your second part of your last response, you are stating that you are trying to then patch some other collection?  What is the purpose of the extra column called Copy?  I'm a little confused on what you are trying to do, but I think you might be over complicating it a bit.  I can't tell for sure as the images are hard to see.

_____________________________________________________________________________________
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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Thanks @RandyHayes  patching with ID worked ! This solved my issue. But then when I am patching my collection to sharepoint list its throwing me an error  regarding the version  number as read only even though I am not changing any version number.

 

I have attached the image 

 

My formula is Patch(SPlist,CollectionName)

 

AishG_1-1634406983361.png

 

 

RandyHayes
Super User
Super User

@AishG 

It is that your collection contains all record columns and some you might not be interested in changing/using.  SO, I would omit them from the collection when you gather it, or use a ShowColumns on your collection in the patch to only expose the columns you do want to update.

_____________________________________________________________________________________
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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (3,321)