In this PowerApps Tutorial for Beginners (PowerApps bulk update using the ForAll patch function) tutorial, we will learn how to update bulk records at a time using the PowerApps ForAll patch function in the SharePoint list. In this demo, we will show how we can insert or update multiple records to the SharePoint list using the PowerApps ForAll patch function.
What you will learn from this article?
- How to perform bulk update operation in SharePoint list using ForAll patch function?
- What is the importance of the ID parameter for the patch function?
- How to filter the gallery control items based on the currently logged-in user?
- The drawback of the ForAll loop and patch function in PowerApps.
PowerApps bulk update using ForAll patch function – add multiple items to SharePoint list
In the above demo, we have added the data table control at the top of the screen to display the updated SharePoint list item data (we assume, you know to connect to the SharePoint list from PowerApps, if you need help, you can refer to our article – PowerApps SharePoint connection step by step ). And below that, we have added a gallery control whose data source is the SharePoint list (‘PO Line Items’), this is just an example, you can connect to any SharePoint list.
Select the list of checkboxes for the approval or rejection of the PO against the purchase order number displayed in the gallery control, then click on the “Update Selected PO” button. Let us see, how this works practically.
Once we select the purchase order number checkboxes from the PowerApps gallery control and click on the “Update Selected PO” button, the value of the “IsPOApproved” column will be updated to true from false (in the code we are just updating a single column for this PoC).
Now let us click on the “Update Selected PO” button.
Notes:
- Once we have clicked on the “Update Selected PO” button, the value of the “IsPOApproved” columns has been changed to true from false for the selective purchase orders.
- Now, the gallery control becomes empty as we have set a filter on this gallery control only to display the value where the “IsPOApproved” value is false.
Now, let’s verify the SharePoint list.
Go to the SharePoint list and see that “IsPOApproved” has been updated to “yes” value for the “PO0003” and “PO0004” purchase orders.
Note:
- The “IsPOApproved” column is the type of Yes/No, however, on the PowerApps side when it gets rendered, it displays as a true or false value, we will explore and update this post later on about the reason.
PowerApps bulk update using ForAll patch function – Technical implementation
Below is the step-by-step implementation:
Filter PowerApps data table items based on the logged-in user
Follow step # 1 for this implementation:
Step1: Filter PowerApps data table items based on the logged-in user
Add a data table control to the screen.
For the items property add the below text:
Filter('PO Line Items', POApproverName.DisplayName=User().FullName)
In the above filter, we are getting the data from the ‘PO Line Items’ SharePoint list, and adding filter conditions to get the list items if the logged-in user is the purchase order approver (POApproverName is the column name).
Similarly, add a gallery control to the screen.
Filter PowerApps gallery control items based on the logged-in user
Follow step # 2 for this implementation:
Step2: Filter PowerApps gallery control items based on the logged-in user
Add a gallery control to the screen.
For the items property of the gallery control add the below text:
Filter('PO Line Items', POApproverName.DisplayName=User().FullName && IsPOApproved=false)
In the above filter, we are getting the data from the ‘PO Line Items’ SharePoint list, and adding filter conditions to get the list items if the logged-in user is the purchase order approver (POApproverName is the column name) and if the “IsPOApproved” is equal to false.
Update SharePoint list from the PowerApps Gallery selected items
Follow step # 3 for this implementation:
Step3: Update the SharePoint list from the PowerApps Gallery selected items
Below is the code to submit data to the SharePoint list using the ForAll loop and Patch function in PowerApps.
ForAll( Gallery1_1.AllItems, Patch('PO Line Items', { ID: ID, IsPOApproved: If( Checkbox3.Value = true, true, false ) }))
Note:
- In the above code, the “ID” column is very important, it is a SharePoint unique column, bypassing the ID column parameter, the first code will try to find the item in the list, if it is found, then it will update that row.
- If we do not pass the ID column, it will create new items in the list.
- Here, other than the ID column, we have passed another column as a parameter i.e. “IsPOApproved” (boolean).
- We can pass column parameters as many as we want in the form of the JSON format.
The ‘ID’ column parameter is a must for the update operation, otherwise, you will end up with multiple new items in the SharePoint list, which leads you to confusion, so, don’t forget to add the ID column in the parameter list.
PowerApps bulk update: The drawback of the ForAll loop and patch function in PowerApps
From the performance point of view, the ForAll loop and patch function is not recommended, it is good if you have fewer items in the list, however, for the larger list items, this technique is not recommended, as this will slow down the performance as this will loop through each item in the data connection list and see if there are any changes in the columns mentioned in the parameter (here for example, “IsPOApproved”), the code will update that column values, the bottom line is, this method time-consuming. In our next article, we will show how we can update the list items in the SharePoint list faster. So, please keep reading these articles and follow our site for upcoming articles.
Summary: What we have learned from this article (PowerApps bulk update)?
Thus, in this article, we have learned the below with respect to the ForAll loop and patch function in PowerApps:
- How to perform bulk update operation in SharePoint list using ForAll patch function?
- What is the importance of the ID parameter for the patch function?
- How to filter the gallery control items based on the currently logged-in user?
- The drawback of the ForAll loop and patch function in PowerApps.
See Also: PowerApps Tutorial
You may also like the below PowerApps articles:
- PowerApps repeating section data to SharePoint list
- Read PowerApps toggle control value
- PowerApps: Hide and show textbox based on dropdown selection
- Change PowerApps dropdown sample value to custom options
- How to send email from PowerApps button click?
- How to open outlook from PowerApps step by step?
- Create your first chatbot in PowerApps step by step
- Cascading dropdown in PowerApps using SharePoint data
- CRUD operations in PowerApps using SharePoint online list
- CRUD Operation in PowerApps Using Excel OneDrive
- Phone number and email validation in PowerApps
- Connect to a SharePoint list in PowerApps step by step
- Collection variable in PowerApps
- Understand the difference between Set and UpdateContext function
- String concatenation function in PowerApps
- 3 ways to create Power Apps – Types of Power Apps
- Overview view of PowerApps development environment in Power Platform
- Customize SharePoint List Forms Using PowerApps step by step – Office 365
- Create free development environment using Power Apps Community Plan
- Show or hide columns conditionally in SharePoint list form
- SharePoint Online – Power Automate: How to Export and Import Microsoft Team Flows across environment
Buy SharePoint Online & Office 365 administration eBook
Buy the premium version of SharePoint Online & Office 365 administration eBook from here:
Reference URL