Patch Function in Canvas app
1. Create A New Record With Power Apps Patch Function
Syntax
Patch(Datasource, BaseRecord, NewRecord)
Input
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
| 2 | Alice Lemon | 0958 | 11/03/2015 | true |
| 3 | David Johnson | 0563 | 08/15/2013 | false |
Code
Patch(
Employees,
Defaults(Employees),
{
FullName: "Sarah Green",
EmployeeNumber: 1002,
HireDate: Date(2018,3,14),
Active: true
}
)Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
| 2 | Alice Lemon | 0958 | 11/03/2015 | true |
| 3 | David Johnson | 0563 | 08/15/2013 | false |
| 4 | Sarah Green | 1002 | 03/14/2018 | true |
2. Update An Existing Record Using Power Apps Patch Function
Syntax
Patch(Datasource, BaseRecord, ChangeRecord)
Input
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
| 2 | Alice Lemon | 0958 | 11/03/2015 | true |
| 3 | David Johnson | 0563 | 08/15/2013 | false |
| 4 | Sarah Green | 1002 | 03/14/2018 | true |
Code
Patch(
Employees,
LookUp(
Employees,
ID=4
),
{
FullName: "Sarah Brown",
EmployeeNumber: 1003
}
)Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
| 2 | Alice Lemon | 0958 | 11/03/2015 | true |
| 3 | David Johnson | 0563 | 08/15/2013 | false |
| 4 | Sarah Brown | 1003 | 03/14/2018 | true |
3. Get The Result Of The Patch Function
Syntax
Set(VariableName, Patch(Datasource, BaseRecord, ChangeRecord))
Input
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | Created | Created By | … |
| 1 | Matthew Devaney | 1050 | 05/08/2022 | Matthew Devaney | … |
| 2 | Alice Lemon | 0958 | 05/10/2022 | Matthew Devaney | … |
| 3 | David Johnson | 0563 | 05/13/2022 | Matthew Devaney | … |
| 4 | Sarah Green | 1002 | 05/13/2022 | Matthew Devaney | … |
Code
Set(
varEmployeeCurrent,
Patch(
Employees,
Default(Employees),
{
FullName: "Kelly Smith",
EmployeeNumber: 1066
}
)
)Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | Created | Created By | … |
| 1 | Matthew Devaney | 1050 | 05/08/2022 | Matthew Devaney | … |
| 2 | Alice Lemon | 0958 | 05/10/2022 | Matthew Devaney | … |
| 3 | David Johnson | 0563 | 05/13/2022 | Matthew Devaney | … |
| 4 | Sarah Green | 1002 | 05/13/2022 | Matthew Devaney | … |
| 5 | Kelly Smith | 1066 | 05/29/2022 | Matthew Devaney | … |
varEmployeeCurrent record in Power Apps
{
ID: 5,
FullName: "Kelly Smith",
EmployeeNumber: 1066,
'Created By': Date(2022, 05, 29),
Created: Matthew Devaney,
Modified: Date(2022, 05, 29),
Modified By: Matthew Devaney
}
4. Create Multiple New Records With Power Apps Patch Function
Syntax
Patch(Datasource, BaseRecordsTable, NewRecordsTable)
Input
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
| 2 | Alice Lemon | 0958 | 11/03/2015 | true |
| 3 | David Johnson | 0563 | 08/15/2013 | false |
| 4 | Sarah Green | 1002 | 03/14/2018 | true |
| 5 | Kelly Smith | 1066 | 05/20/2022 | true |
Code
ClearCollect(
colNewEmployees,
Table(
Employees@{
FullName: "Mary Baker",
EmployeeNumber: 0798,
HireDate: Date(2022, 06, 06),
Active: true
},
Employees@{
FullName: "John Miller",
EmployeeNumber: 1203,
HireDate: Date(2022, 06, 11),
Active: true
},
Employees@{
FullName: "Susan Wright",
EmployeeNumber: 0590,
HireDate: Date(2022, 06, 23),
Active: true
}
)
);
Patch(
Employees,
ForAll(
Sequence(CountRows(colNewEmployees)),
Defaults(Employees)
),
colNewEmployees
);Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
| 2 | Alice Lemon | 0958 | 11/03/2015 | true |
| 3 | David Johnson | 0563 | 08/15/2013 | false |
| 4 | Sarah Green | 1002 | 03/14/2018 | true |
| 5 | Kelly Smith | 1066 | 05/20/2022 | true |
| 6 | Mary Baker | 0798 | 06/06/2022 | true |
| 7 | John Miller | 1203 | 06/11/2022 | true |
| 8 | Susan Wright | 0590 | 06/23/2022 | true |
5. Edit Multiple Existing Records Using Power Apps Patch Function
Syntax
Patch(Datasource, BaseRecordsTable, UpdateRecordsTable)
Input
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
| 2 | Alice Lemon | 0958 | 11/03/2015 | true |
| 3 | David Johnson | 0563 | 08/15/2013 | false |
| 4 | Sarah Green | 1002 | 03/14/2018 | true |
| 5 | Kelly Smith | 1066 | 05/20/2022 | true |
Code
ClearCollect(
colUpdateEmployees,
Table(
Employees@{
ID: 2,
FullName: "Alice Henderson",
EmployeeNumber: 1001
},
Employees@{
ID: 4,
Active: false
},
Employees@{
ID: 5,
HireDate: Date(2022, 08, 01)
}
)
);
Patch(
Employees,
ShowColumns(
colUpdateEmployees,
"ID"
),
colUpdateEmployees
);Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
| 2 | Alice Henderson | 1001 | 11/03/2015 | true |
| 3 | David Johnson | 0563 | 08/15/2013 | false |
| 4 | Sarah Green | 1002 | 03/14/2018 | false |
| 5 | Kelly Smith | 1066 | 08/01/2022 | true |
6. Upsert Multiple Records With Power Apps Patch Function
Syntax
Patch(Datasource, BaseRecordsTable, UpsertRecordsTable)
Input
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
| 2 | Alice Lemon | 0958 | 11/03/2015 | true |
| 3 | David Johnson | 0563 | 08/15/2013 | false |
Code
ClearCollect(
colUpsertEmployees,
Table(
Employees@{
ID: 2,
FullName: "Alice Henderson",
EmployeeNumber: 1001
},
Employees@{
ID: Blank(),
FullName: "Sarah Green",
EmployeeNumber: 1002,
HireDate: Date(2018, 03, 14),
Active: false
},
Employees@{
ID: Blank(),
FullName: "Kelly Smith",
EmployeeNumber: 1066,
HireDate: Date(2022, 05, 20),
Active: true
}
)
);
Patch(
Employees,
colUpsertEmployees
);Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
| 2 | Alice Henderson | 1001 | 11/03/2015 | true |
| 3 | David Johnson | 0563 | 08/15/2013 | false |
| 4 | Sarah Green | 1002 | 03/14/2018 | false |
| 5 | Kelly Smith | 1066 | 08/01/2022 | true |
7. Change Values In A Record Variable Using Power Apps Patch Function
Syntax
Patch(Record1, Record2)
Input
Record stored in a global variable named gblEmployee
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1050 | 05/28/2010 | true |
Code
Patch(
gblEmployee,
{EmployeeNumber: 1063}
);Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Matthew Devaney | 1063 | 05/28/2010 | true |
More Power Apps Patch Function Tips And Tricks
Want to learn more about the Patch function? Check out these awesome otherarticles I’ve written:
Everything You Need To Know About Power Apps Patch Forms
A full tutorial on how to build a Power Apps patch form including the topics: form submissions, data validation, error-handling and updating a previously submitted record.
Patch Multiple Records In Power Apps 10X Faster
A nifty trick I discovered to submit multiple records at once really really quickly.
Power Apps Patch Function Examples For Every SharePoint Column Type
Example of how to patch every SharePoint column type in an easy to read format.
Learn how to check a form for errors on submission and eliminate the possibility to losing entered data.
Power Apps Excel-Style Editable Table
Make an excel-style table in Power Apps you users will love by using the Patch function
Comments
Post a Comment