PowerApps Patch Function With Complex Columns

Introduction

 
PowerApps Patch function is used to create and modify records in SharePoint. The values of specific fields are modified without affecting other properties.
 
In this article we will see how to create records in  aSharePoint list using PowerApps Patch function with SharePoint complex columns like Lookup field, User field, and Choice field.
 
Example 
 
Let's start the step by step implementation.
 
First we will create a SharePoint list and then we will create the above-mentioned complex fields.
 
PowerApps Patch Fuction With Complex Columns
 
Go to the PowerApps > Click on Create > Select Canvas app from blank > Set app name and select format.
 

Add required controls

  1. Add labels for Name , Address , DOB , Lookup , Manager and Gender 
  2. Add Dropdown for Lookup and Manager fields
  3. Text input (Single line) for Name
  4. Text Input (Multi line) for Address 
  5. Radio button for Gender 
  6. Date Picker for DOB as below image.
PowerApps Patch Fuction With Complex Columns
 
Now set the data source to save the record in the SharePoint list.
  • Go to the View on top ribbon > Select Data source > Search SharePoint > Add connection > Connect to the SharePoint Site > Select lists (Lookup list and list in which we create the record).
  • Add another Data Source > Office 365 User - For adding  users in manager dropdown.
  • Then map Lookup, Gender and Manager columns as below,
Manager
 
Set Property Items Office365Users.SearchUser() and then move to the properties on right corner > set Value - DisplayName 
 
Lookup
 
Set Property Items - [Lookup List Name].Title (eg. Department.Title)
 
Gender
 
Set Property Items - ["Male","Female"]
 
Patch Syntax to save records in SharePoint list:
  1. Patch(datasource,  
  2.     Defaults(datasource),  
  3.     {  
  4.         Column name: value  
  5.         ….  
  6.     }  
  7.  )  
Now we will save records in SharePoint list using Patch function as below,
  1. Patch('Employees Information'),  
  2.    Defaults('Employees Information'),  
  3.    {  
  4.       Title : txtName.Text,  
  5.       Address : txtAddress.Text,  
  6.       DOB:DatePicker1.SelectedDate,  
  7.       Gender: {  
  8.          '@odata.type'"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
  9.          Value: <radio button selected value>  
  10.       },  
  11.       Lookup:{  
  12.          '@odata.type'"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
  13.          Id: <Lookup ID>   
  14.          Value: <Lookup Value> //dropdown selected value  
  15.       },  
  16.       Manager: {  
  17.          '@odata.type'"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
  18.          Claims: "i:0#.f|membership|" & Lower(  
  19.             LookUp(  
  20.                Office365Users.SearchUser(),  
  21.                DisplayName = ddManager.Selected.DisplayName   
  22.             ).Mail  
  23.          ),  
  24.          Email: LookUp(  
  25.             Office365Users.SearchUser(),  
  26.                DisplayName = ddManager.Selected.DisplayName  
  27.          ).Mail,  
  28.          Picture: "",  
  29.          JobTitle: "",  
  30.          Department: "",  
  31.          DisplayName: ddManager.Selected.DisplayName,   
  32.  } });  

Summary

 
In this article , we have seen how to use patch function to save records in Sharepoint with complex columns, how to connect data source, and how to map controls.
 
I hope this helps.
 
Sharing is caring.


Similar Articles