cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Help! How can I patch changes to a SharePoint list from a collection?

I have seen a lot of posts on the community about this but am still not able to make the patch work. I have a SharePoint list (ExpenseClaims). I have a gallery that displays the items in the list. I have a toggle control that I want to use in the gallery to collect changes that will later be patched to a Yes/No column in the SharePoint list.

Picture1.png

How can I go about collecting all of the changes made to items in the gallery and patching them to SharePoint so as to update items that already exist? I know I need an OnSelect collect action for the toggle and a Patch on a button.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

@v-xida-msft and @gabibalaban, thank y'all both for your suggestions. After doing a bit more research, I found that this blog post from Microsoft largely solved the issue with some modifications on my part such as the use of an UpdateIf to correct the logged collection item.

 

Essentially, I set the Toggle button to the following code:

If(
    !IsBlank(
        LookUp(
            ToggledItems,
            ID = ThisItem.ID
        )
    ),
    RemoveIf(
        ToggledItems,
        ID = ThisItem.ID
    ),
    Collect(
        ToggledItems,
        {
            ID: ThisItem.ID,
            Paid: ThisItem.Paid
        }
    );
    UpdateIf(
        ToggledItems,
        ID = ThisItem.ID,
        {Paid: tglPaid_1.Value}
    )
)

Then, I configured a button outside of the gallery with the following code:

Patch(
    ExpenseClaims,
    ToggledItems
);
Clear(ToggledItems);
Refresh(ExpenseClaims)

It now works like a charm. When I make changes with the toggle, I can patch the corresponding collection that logs changed items to my SP list. I will do more testing with Complex column types.

 

Thanks again for all your help.

View solution in original post

9 REPLIES 9
Highlighted
Memorable Member
Memorable Member

Actually you need a button outside the gallery to do the PATCH thing. 

Please adapt this to your OnSelect property of the button:

ForAll (Gallery.AllItems,

          If(Toggle1, Patch(....)

          )

Highlighted

@gabibalaban, thank you for responding. If I have a list containing thousands of items, won't that patch every single item in the Gallery back to the dataset?

 

Currently, gallery's items come from the SharePoint list and the toggle's default item is ThisItem.PayStatus. I want to only patch items in the gallery that I change the toggle on; the toggle could change from Paid to Unpaid or from Unpaid to Paid.

Highlighted

This is what FORALL is meant to be ... to move from Gallery.allitems and test if the toggle is true. If it is true, the PATCH ().

Just give it a try, put it on ONSELECT property of a button of course adapted to your controls.

Highlighted

@gabibalaban, and what should the PATCH look like? In this scenario, the SharePoint list ExpenseClaims has two columns: Title and PayStatus. How can I patch changes made to all toggles in the gallery to the SP list?

 

As an example, here is the SharePoint list as reflected in my gallery currently:

 

Picture1.png

I want to patch Expense 1's change to Paid and Expense 2's change to Unpaid.

 

Picture2.png

Highlighted

I think you need a local collection to store the data for gallery.

 

1.Set ONVISIBILE() property put something like:

     CLEARCOLLECT(LocalCollection, YourSharePointList)

 

2.Set ITEMS property of the Gallery to:

    LocalCollection

This modification shouldn't damage your app. 

3. Insert a button and set ONSELECT property for this to:

      ForAll(

            GaleryNAME.AllItems,

                      Patch(YourSharePointList, LookUp(LocalCollection,ID=LocalCollection[@ID],{NameOfColumn:ToggleButtonName}) 

 

I used a small workaround passing all data to local to avoid delegation warning inside PATCH.

I don't if it is the smartest solution, but it works. 

You can also can use a variable inside gallery to flag if the values are changed and after that modify the ForAll loop based on the value of this variable but it hard to explain here. 

 

I want to see others ideas to help you with this problem. Here are some much more smarter guys then me.  

 

Highlighted

@gabibalaban, I appreciate your ongoing help. Question on your last post: won't storing the list to a local collection not work if the list is over 500 (max 2000) items?

Highlighted

I think you can use a filter.

It is hard to believe that you have to check more than 500 (2000 expenses) all at once. But if it is really necessary, you can find interesting article about how to avoid this limits. 

Here is one:

https://powerusers.microsoft.com/t5/General-Discussion/500-item-limit-in-CDM-entity-search-filter-ne...

Anyway, in my opinion it is better to find solutions to delegate filter to SharePoint. 

Highlighted

Hi @pwrappr01 ,

Do you want to patch the Toggle changes Item from your Gallery back to your SP List?

 

Based on the needs that you mentioned, I think the ForAll function and Patch function could achieve your needs. I have made a test on my side, please consider take a try with the following workaround:

Set the OnSelect property of "Submit" button outside the Gallery to following:

ForAll(
       RenameColumns(Gallery1.AllItems, "ID", "ID1"),
       If(
          PayStatus <> Toggle1.Value,
          Patch(
                ExpenseClaims,
                LookUp(ExpenseClaims, ID = ID1),
                {
                  PayStatus: Toggle1.Value
                }
          )
       )
)

or

ForAll(
       RenameColumns(Gallery1.AllItems, "ID", "ID1"),
       Patch(
                ExpenseClaims,
                LookUp(ExpenseClaims, ID = ID1),
                {
                  PayStatus: If(Toggle1.Value, true, false)
                }
      )
)

Note: Above formula would be applied to each item in your Gallery.

 

Actually, I think it is not necessary to add a button outside the Gallery to submit all changes once time. As a direct solution, you could consider set the OnSelect property of the Toggle control in your Gallery to following:

If(
   Toggle1.Value,
   Patch(ExpenseClaims, ThisItem, {PayStatus: true}),
   Patch(ExpenseClaims, ThisItem, {PayStatus: false})
)

 

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.
Highlighted

@v-xida-msft and @gabibalaban, thank y'all both for your suggestions. After doing a bit more research, I found that this blog post from Microsoft largely solved the issue with some modifications on my part such as the use of an UpdateIf to correct the logged collection item.

 

Essentially, I set the Toggle button to the following code:

If(
    !IsBlank(
        LookUp(
            ToggledItems,
            ID = ThisItem.ID
        )
    ),
    RemoveIf(
        ToggledItems,
        ID = ThisItem.ID
    ),
    Collect(
        ToggledItems,
        {
            ID: ThisItem.ID,
            Paid: ThisItem.Paid
        }
    );
    UpdateIf(
        ToggledItems,
        ID = ThisItem.ID,
        {Paid: tglPaid_1.Value}
    )
)

Then, I configured a button outside of the gallery with the following code:

Patch(
    ExpenseClaims,
    ToggledItems
);
Clear(ToggledItems);
Refresh(ExpenseClaims)

It now works like a charm. When I make changes with the toggle, I can patch the corresponding collection that logs changed items to my SP list. I will do more testing with Complex column types.

 

Thanks again for all your help.

View solution in original post

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (4,215)