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
Step 2 - Create User Name field with person or group
Step 3 - Create Qualification Field with Choice data type along with data like (MCA, BCA, BE)
Step 4 - Create Department list, along with below data
Step 5 - Create Department Look upfield in the list
Step 6 - After adding all columns, Go To PowerApps > Refresh Data source if using existing PowerApps
Step 7 - Add Radio button to the screen
Step 8 - Select Radio button and in Property > Select Items and Add Choices([@Employees].Gender)
Step 9 - Add Dropdown on screen
Step 10 - Go to Dropdown > Item property , Add ["MCA","BCA","BE"] as data to it.
Step 11 - Now Add Combo box on Screen
Step 12 - Select Combo box > Right Panel Select Data source > Connectors
Step 13 - Select Department list from SharePoint as a Data Source list
Step 14 - Select Combo Box > Select SearchFields property and change it to Title
Step 15 - Select Combo Box > Select DisplayFields property and change it to Title
Step 16 - Now we can see that values are bound to the dropdown
Step 17 - Add another dropdown for User input
Step 18 - Add 2 buttons for Save and Reset
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
}
});
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
Step 21 - As we can see in the list below data is added successfully
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..!!!