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

Capture results of ForAll Patch

I have a canvas app with a gallery. The source for the gallery is a SharePoint list. Each item in the gallery has a check box where the user can select the item. Then there is a "Update" button. After the user has made his selections using the check boxes he should click the Update button. In the OnSelect even of the button, there is a ForAll block that iterates through the items in the gallery and checks which ones have their check boxes selected. If a check box for a particular item is selected, the item is updated using the Patch function. I would like to capture the results of the Patch function, but seems I can't use UpdateContext, Set, ClearCollect, Collect in the ForAll function. How do I inspect the records that were updated? I read this, but I just want to inspect the record, not handle errors, so this is not quite what I'm looking for. Showing some partial code below of what I'm trying to do.

 

 

//Submit.OnSelect
ForAll(
    Gallery2_1.AllItems,
    If(
        ThisRecord.Checkbox1.Value = true, //ThisRecord refers to current item in gallery
        Patch(
            'SharePoint Source',
            LookUp(
                'SharePoint Source',
                ThisRecord.Title exactin Title
            ),
            {
                'Is taken': true,
                'Is taken2': "Yes"
            }
        );
//Print message to screen to inspect
        Notify(
            //This is where I get stuck - how to reference the result of the Patch?
"Something should go here"
            ,
            NotificationType.Success
        );
    )
)

 

 

****

Edit:

For backgound, I wrapped the ForAll in an IfError. When I run the code I get no error. but my patch doesn't update the existing record. But when I use Defaults in the Patch it correctly creates a new record. I thought the issue might be with the LookUp function, so i created a separate button and text box to test the LookUp function and that seems to work correctly. I can't understand why my Patch is not updating the existing record. That's why I want to inspect the results of the Patch function.

***

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @Donn ,

Two things - ForAll is not designed to "loop" through records (it can do this, but with performance penalties), it creates a Table that can be Patched in one action. Secondly, the below is just an idea on what you might want to present to the user.

With(
   {
      wGal: 
      AddColumns(
         Filter(
            Gallery2_1.AllItems,
            Checkbox1.Value
         ),
         "galID",
         LookUp(
            'SharePoint Source' As aList,
            aList.Title = Title
         ).ID
      )
   },
   With(
      {
         wResult: 
         Concat(
            wGal,
            Title,
            " / "
         )
      },
      Patch(
         'SharePoint Source',
         ForAll(
            wGal As aPatch,
            {
               ID: aPatch.galID,
               'Is taken': true,
               'Is taken2': "Yes"
            }
         )
      );
      Notify(
         "Records updated - " & wResult,
         NotificationType.Success
      )
   )
)

If you have the ID of the SP List item in your gallery, there is no need for the AddColumns - just refer to the ID in the Patch at the bottom.

With(
   {
      wGal: 
      Filter(
         Gallery2_1.AllItems,
         Checkbox1.Value
      )
   },
   With(
      {
         wResult: 
         Concat(
            wGal,
            Title,
            " / "
         )
      },
      Patch(
         'SharePoint Source',
         ForAll(
            wGal As aPatch,
            {
               ID: aPatch.ID,
               'Is taken': true,
               'Is taken2': "Yes"
            }
         )
      );
      Notify(
         "Records updated - " & wResult,
         NotificationType.Success
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

View solution in original post

5 REPLIES 5
WarrenBelz
Super User
Super User

Hi @Donn ,

Two things - ForAll is not designed to "loop" through records (it can do this, but with performance penalties), it creates a Table that can be Patched in one action. Secondly, the below is just an idea on what you might want to present to the user.

With(
   {
      wGal: 
      AddColumns(
         Filter(
            Gallery2_1.AllItems,
            Checkbox1.Value
         ),
         "galID",
         LookUp(
            'SharePoint Source' As aList,
            aList.Title = Title
         ).ID
      )
   },
   With(
      {
         wResult: 
         Concat(
            wGal,
            Title,
            " / "
         )
      },
      Patch(
         'SharePoint Source',
         ForAll(
            wGal As aPatch,
            {
               ID: aPatch.galID,
               'Is taken': true,
               'Is taken2': "Yes"
            }
         )
      );
      Notify(
         "Records updated - " & wResult,
         NotificationType.Success
      )
   )
)

If you have the ID of the SP List item in your gallery, there is no need for the AddColumns - just refer to the ID in the Patch at the bottom.

With(
   {
      wGal: 
      Filter(
         Gallery2_1.AllItems,
         Checkbox1.Value
      )
   },
   With(
      {
         wResult: 
         Concat(
            wGal,
            Title,
            " / "
         )
      },
      Patch(
         'SharePoint Source',
         ForAll(
            wGal As aPatch,
            {
               ID: aPatch.ID,
               'Is taken': true,
               'Is taken2': "Yes"
            }
         )
      );
      Notify(
         "Records updated - " & wResult,
         NotificationType.Success
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Thanks @WarrenBelz. I don't quite understand why there are two Patches. The inner patch updates the records, one at at time. What is the purpose of the outer Patch?

@Donn ,

I have reposted another idea - that was a typing error, but still had issues.

Thanks. That makes sense. One last question: the patch only has two arguments. looks like argument for base record table is missing. Will it work as is (I haven't tried to run this code yet)?

Hi @Donn ,

It should work (the structure is correct if your values are) - what you are actually doing is sending the entire table in one action. You need the ID in there as it is unique and cannot be changed and SharePoint then assumes you want to update each record (and does so). You will notice a substantial (the more records, the bigger) performance improvement with this structure as opposed to looping through individual Patches.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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