Use Of Patch Function With Complex Types In PowerApps

In this article, we will learn about the usage of the Patch function with complex data types such as People or Group, lookup, dropdown, and Choice column.

Create another list named Department with ID and Title field. Add some default values like (IT, HR, Accounting, Marketing)

Now add some other fields in the Employee list like,

  • Gender Choice
  • Department Lookup
  • User Person or Group
  • Qualification Dropdown (MCA,BCA,BE)

Step 1 - Create Gender field with Choice column

Patch Function In PowerApps

Step 2 - Create User Name field with person or group

Patch Function In PowerApps

Step 3 - Create Qualification Field with Choice data type along with data like (MCA, BCA, BE)

Patch Function In PowerApps

Step 4 - Create Department list, along with below data

Patch Function In PowerApps

Step 5 - Create Department Look upfield in the list

Patch Function In PowerApps

Step 6 - After adding all columns, Go To PowerApps > Refresh Data source if using existing PowerApps

Step 7 - Add Radio button to the screen

Patch Function In PowerApps

Step 8 - Select Radio button and in Property > Select Items and Add Choices([@Employees].Gender)

Patch Function In PowerApps

Step 9 - Add Dropdown on screen

Patch Function In PowerApps

Step 10 - Go to Dropdown > Item property , Add ["MCA","BCA","BE"] as data to it.

Patch Function In PowerApps

Step 11 - Now Add Combo box on Screen

Patch Function In PowerApps

Step 12 - Select Combo box > Right Panel Select Data source > Connectors

Patch Function In PowerApps

Step 13 - Select Department list from SharePoint as a Data Source list

Patch Function In PowerApps

Step 14 - Select Combo Box > Select SearchFields property and change it to Title

Patch Function In PowerApps

Step 15 - Select Combo Box > Select DisplayFields property and change it to Title

Patch Function In PowerApps

Step 16 - Now we can see that values are bound to the dropdown

Patch Function In PowerApps

Step 17 - Add another dropdown for User input

Patch Function In PowerApps

Patch Function In PowerApps

Step 18 - Add 2 buttons for Save and Reset

Patch Function In PowerApps

Step 19 - OnClick of save button add Patch code as below,

Patch(Employees,Defaults(Employees), 
{ 
    Title:txtTitle.Text, 
    Gender: { 
    '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser", 
     Value:Radio1.Selected.Value 
    }, 
    Qualification:{ 
    '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser", 
     Value:Dropdown1.Selected.Value 
    }, 
    'User Name': { 
    '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser", 
     Claims:"i:0#.f|membership|" & ComboBox2.Selected.Mail, 
     Department:"", 
     DisplayName:ComboBox2.Selected.DisplayName, 
     Email:ComboBox2.Selected.Mail, 
     JobTitle:"", 
     Picture:"" 
   }, 
      Department:{ 
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser", I 
      Id:Value(ComboBox1.Selected.ID), 
      Value:ComboBox1.Selected.Title 
      } 
});

Patch Function In PowerApps

As above, for storing Person or User Group we need below format

FieldName: {
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Claims:"i:0#.f|membership|" & <control selected value>,
Department:"",
DisplayName: <control selected value>,
Email: <control.Selected.Value>,
JobTitle:"",
Picture:""
}

for storing the Choice column, dropdown we need below format

FieldName:{
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Value:<Control.Selected.Value>
},

for lookup column,

FieldName:{
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
Id:<Control.Selected.ID>,
Value:<Control.Selected.Title>
}

Step 20 - Fill in detail and click on the Save button

Patch Function In PowerApps

Step 21 - As we can see in the list below data is added successfully

Patch Function In PowerApps

So in this way, we can save data for a complex data type into SharePoint list using the Patch function.

Hope this helps.

Happy coding..!!!


Similar Articles