cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
notj
Level: Powered On

Need assistance with patch/update collections and SharePoint list. I'm creating duplicates instead of updating.

I have a SharePoint list called SiteVisitDetails. 

I have a Gallery(Gallery1_4). It's Items property is set to a collection. (svditems)

I have a button(button4). It creates a new line in the gallery.

I have a button(button6). It's OnSelect property is set to the following:

 

ClearCollect(collsvdtemp, Gallery1_4.AllItems);
Patch(SiteVisitDetails, collsvdtemp);
Navigate([@ScreenSuccess], ScreenTransition.Cover)

 

 

When I click button6, it does not update the existing items in the gallery, it instead creates duplicates. How can I make it update the existing and then add any that were not previously existing to the SP list?

 

Do I need to do something like ForAll(Galley1_4, if(id=id, Update(record), Patch(record))? 

 

I've been circling around and around with this for quite a while now.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Need assistance with patch/update collections and SharePoint list. I'm creating duplicates instead of updating.

Hi @notj ,

Do you want to update existing items in your SP List with the Items within your Gallery?

Is the svditems collection collected from your SiteVisitDetails List?

 

Based on the formula you provided, I think there is something wrong with it. I have made a test on my side, please consider take a try with the following workaround:

Set the OnSelect property of the Button6 to following:

ForAll(
       RenameColumns(Gallery1_4.AllItems, "ID", "ID1"),
       If(
          !IsBlank(LookUp(SiteVisitDetails, ID = ID1)),
           Patch(                             // Update existing records
                  SiteVisitDetails,
                  LookUp(SiteVisitDetails, ID = ID1),
                  {
                    Column1: TextInput1.Text,
                    Column2: TextInput2.Text,
                    ... 
                  }
           ),
           Patch(                              // Add new records existd in your Gallery
                 SiteVisitDetails,
                 Defaults(SiteVisitDetails),
                 {
                   Title: TitleTextBox.Text,
                   Column1: TextInput1.Text,
                   Column2: TextInput2.Text,
                   ...
                 }
           )
       )
);
ClearCollect(svditems, SiteVisitDetails);  //  Update the svditems collection from your SP list again
Navigate([@ScreenSuccess], ScreenTransition.Cover)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Eelman
Level 8

Re: Need assistance with patch/update collections and SharePoint list. I'm creating duplicates instead of updating.

@notj 

I'm guessing that svditems is created using SiteVisitDetails? Something like this:

ClearCollect ( svditems, SiteVisitDetails)

 

If not, this is what I would do to ensure that svditems is built using the same schema as SiteVisitDetails, which makes Patching easier.

 

Then,

button4.OnSelect = Patch( svditems, Defaults( svditems), { [your details here] } )

- this creates a new item WITHOUT an ID in svditems, and we use that detail below in the SP Patch. Make sure all REQUIRED fields from SiteVisitDetails have values

 

Button6.OnSelect = ClearCollect(svditemsTEMP, Filter(svditems, IsBlank(ID))); Patch(ECMApprovals,svditemsTEMP); ClearCollect ( svditems, SiteVisitDetails)

- this creates a collection of NEW records without an ID which is then Patched to SP. Finally, we re-create/update svditems

 

You could add some extra checking to see if svditemsTEMP has any records before you patch if you like eg

If ( CountRows(svditemsTEMP) > 0 , Patch(ECMApprovals,svditemsTEMP) )

 

This seems to work for me so give it a try and let me know how you get on?

 

 

Community Support Team
Community Support Team

Re: Need assistance with patch/update collections and SharePoint list. I'm creating duplicates instead of updating.

Hi @notj ,

Do you want to update existing items in your SP List with the Items within your Gallery?

Is the svditems collection collected from your SiteVisitDetails List?

 

Based on the formula you provided, I think there is something wrong with it. I have made a test on my side, please consider take a try with the following workaround:

Set the OnSelect property of the Button6 to following:

ForAll(
       RenameColumns(Gallery1_4.AllItems, "ID", "ID1"),
       If(
          !IsBlank(LookUp(SiteVisitDetails, ID = ID1)),
           Patch(                             // Update existing records
                  SiteVisitDetails,
                  LookUp(SiteVisitDetails, ID = ID1),
                  {
                    Column1: TextInput1.Text,
                    Column2: TextInput2.Text,
                    ... 
                  }
           ),
           Patch(                              // Add new records existd in your Gallery
                 SiteVisitDetails,
                 Defaults(SiteVisitDetails),
                 {
                   Title: TitleTextBox.Text,
                   Column1: TextInput1.Text,
                   Column2: TextInput2.Text,
                   ...
                 }
           )
       )
);
ClearCollect(svditems, SiteVisitDetails);  //  Update the svditems collection from your SP list again
Navigate([@ScreenSuccess], ScreenTransition.Cover)

 

Please consider take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

notj
Level: Powered On

Re: Need assistance with patch/update collections and SharePoint list. I'm creating duplicates instead of updating.

@Eelman I see what you're doing here. It makes sense, but, I'm guessing it's supposed to say SiteVisitDetails where it says "ECMApprovals", right? Looks like you're reusing something here haha.

ClearCollect(svditemsTEMP, Filter(svditems, IsBlank(ID))); Patch(ECMApprovals,svditemsTEMP); ClearCollect ( svditems, SiteVisitDetails)

The new line patch seems to work well. I was doing it another route but yours works too.

Unfortunately, no matter what I change the fields to(in the gallery, after creating the new line) does not get saved. Either changing an existing item in the gallery or modifying the newly created items.

 

It seems like the collection isn't getting updated after creating the new items, nor when an item is modified. And then the default line is being patched. Does that make sense?

notj
Level: Powered On

Re: Need assistance with patch/update collections and SharePoint list. I'm creating duplicates instead of updating.

@v-xida-msft This didn't work at first, but it's working now. Can you tell me what I'm accomplishing with the RenameColumn part of the code? What's the purpose of renaming ID and then evaluating ID against the new ID1?

notj
Level: Powered On

Re: Need assistance with patch/update collections and SharePoint list. I'm creating duplicates instead of updating.

Edit: I saw what I was doing wrong. I somehow dropped the ForAll when I copied it for the second section. I also understand what you're doing with the RenameColumn. You have to evaluate if the item exists, and in order to do so you take what's in the ID column, make it another column, and then evaluate them against each other, right?


@v-xida-msft I tried to duplicate this for another gallery that's doing pretty much the same thing. The code is below. I get an error on the ID = ID1 part, and it says the equal sign is an invalid argument type, and then also says that ID1 isn't recognized. Any idea what's happening there? It works for the first example and then a gallery with even less fields is erroring out. 

 

RenameColumns(Gallery1_5.AllItems, "ID", "ID1"),
       If(
          !IsBlank(LookUp(SVTList, ID = ID1)),
           Patch(                             // Update existing records
                  SVTList,
                  LookUp(SVTList, ID = ID1),
                  {
                    SVT: textSiteVisitandType_2.Text,
                    Title: Label11.Text
                  }
           ),
           Patch(                              // Add new records existd in your Gallery
                 SVTList,
                 Defaults(SVTList),
                 {
                    SVT: textSiteVisitandType_2.Text,
                    Title: Label11.Text
                 }
           )
       )

 

Eelman
Level 8

Re: Need assistance with patch/update collections and SharePoint list. I'm creating duplicates instead of updating.

@notj  Nice pickup, you are correct, that was my test code haha. I was rushing at work and forgot to edit it to suit your situation. At least you worked it out 🙂

 

Strange it didn't work because it did for me, otherwise I wouldn't have posted that solution. Happy to see you got a solution though.

 

Cheers

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,438)