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 | Jaya Sankar | 1050 | 05/28/2010 | true |
| 2 | Ramesh Babu | 0958 | 11/03/2015 | true |
| 3 | Prasad Kilari | 0563 | 08/15/2013 | false |
Code
Patch(
Employees,
Defaults(Employees),
{
FullName: "Sarah Green",
EmployeeNumber: 1002,
HireDate: Date(2018,3,14),
Active: true
}
)Code language: CSS (css)Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Jaya Sankar | 1050 | 05/28/2010 | true |
| 2 | Ramesh Babu | 0958 | 11/03/2015 | true |
| 3 | Prasad Kilari | 0563 | 08/15/2013 | false |
| 4 | Arvind | 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 | Jaya Sankar | 1050 | 05/28/2010 | true |
| 2 | Ramesh Babu | 0958 | 11/03/2015 | true |
| 3 | Prasad Kilari | 0563 | 08/15/2013 | false |
| 4 | Arvin | 1002 | 03/14/2018 | true |
Code
Patch(
Employees,
LookUp(
Employees,
ID=4
),
{
FullName: "Sarah Brown",
EmployeeNumber: 1003
}
)Code language: JavaScript (javascript)Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Jaya Sankar | 1050 | 05/28/2010 | true |
| 2 | Ramesh Babu | 0958 | 11/03/2015 | true |
| 3 | Prasad Kilari | 0563 | 08/15/2013 | false |
| 4 | Arvind | 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 | Jaya Sankar | 1050 | 05/08/2022 | Matthew Devaney | … |
| 2 | Ramesh Babu | 0958 | 05/10/2022 | Matthew Devaney | … |
| 3 | Prasad Kilari | 0563 | 05/13/2022 | Matthew Devaney | … |
| 4 | Arvind | 1002 | 05/13/2022 | Matthew Devaney | … |
Code
Set(
varEmployeeCurrent,
Patch(
Employees,
Defaults(Employees),
{
FullName: "Kelly Smith",
EmployeeNumber: 1066
}
)
)Code language: CSS (css)Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | Created | Created By | … |
| 1 | Jaya Sankar | 1050 | 05/08/2022 | Matthew Devaney | … |
| 2 | Ramesh Babu | 0958 | 05/10/2022 | Matthew Devaney | … |
| 3 | Prasad Kilari | 0563 | 05/13/2022 | Matthew Devaney | … |
| 4 | Arvind | 1002 | 05/13/2022 | Matthew Devaney | … |
| 5 | AshwinKumar | 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
}Code language: CSS (css)
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 | Jaya Sankar | 1050 | 05/28/2010 | true |
| 2 | Ramesh Babu | 0958 | 11/03/2015 | true |
| 3 | Prasad Kilari | 0563 | 08/15/2013 | false |
| 4 | Arvind | 1002 | 03/14/2018 | true |
| 5 | AshwinKumar | 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
);Code language: JavaScript (javascript)Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Jaya Sankar | 1050 | 05/28/2010 | true |
| 2 | Ramesh Babu | 0958 | 11/03/2015 | true |
| 3 | Prasad Kilari | 0563 | 08/15/2013 | false |
| 4 | Arvin | 1002 | 03/14/2018 | true |
| 5 | AshwinKumar | 1066 | 05/20/2022 | true |
| 6 | Mangala D S | 0798 | 06/06/2022 | true |
| 7 | Sudhamani D S | 1203 | 06/11/2022 | true |
| 8 | Anitha D S | 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 | Jaya Sankar | 1050 | 05/28/2010 | true |
| 2 | Ramesh Babu | 0958 | 11/03/2015 | true |
| 3 | Prasad Kilari | 0563 | 08/15/2013 | false |
| 4 | Arvind | 1002 | 03/14/2018 | true |
| 5 | AshwinKumar | 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
);Code language: JavaScript (javascript)Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Jaya Sankar | 1050 | 05/28/2010 | true |
| 2 | Ramesh Babu | 1001 | 11/03/2015 | true |
| 3 | Prasad Kilari | 0563 | 08/15/2013 | false |
| 4 | Arvind | 1002 | 03/14/2018 | false |
| 5 | AshwinKumar | 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 | Jaya Sankar | 1050 | 05/28/2010 | true |
| 2 | Ramesh babu | 0958 | 11/03/2015 | true |
| 3 | Prasad Kilari | 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
);Code language: JavaScript (javascript)Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Jaya sankar | 1050 | 05/28/2010 | true |
| 2 | Ramesh Babu | 1001 | 11/03/2015 | true |
| 3 | Prasad Kilari | 0563 | 08/15/2013 | false |
| 4 | Arvin | 1002 | 03/14/2018 | false |
| 5 | Ashwinkumar | 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 | Jaya sankar | 1050 | 05/28/2010 | true |
Code
Patch(
gblEmployee,
{EmployeeNumber: 1063}
);Code language: CSS (css)Output
Employees Table In SharePoint
| ID | FullName | EmployeeNumber | HireDate | Active |
| 1 | Jaya Sankar | 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